我想使用 Reeder iPad 应用程序使用的一些技术:
具体来说,我希望导航位于左侧并使用类似的布局。
他们是怎么做到的?它只是位于左侧的标准导航 Controller 吗?项目/缩略图的布局是否只是一个自定义的表格 View ?谢谢。
最佳答案
它不是标准的导航 Controller 。您必须创建自己的 UIView
,将其自身附加到侧面并将 AutoresizingMask
属性设置为 UIViewAutoresizingFlexibleHeight
。通过使用 -drawRect:
和 -layoutSubviews:
方法,使用您想要的按钮设置 View 。根据您想对自定义 View 进行多少抽象,您可以让所有按钮向 UIView
发送消息,然后该 View 会将这些消息传递给委托(delegate)。
例子:
@protocol SideNavigationBarDelegate
- (void)didTapButtonAtIndex:(NSUInteger)buttonIndex;
@end
@interface SideNavigationBar : UIView
@property (strong, nonatomic) id<SideNavigationBarDelegate> delegate;
- (id)initWithDelegate:(id<SideNavigationBarDelegate>)aDelegate;
- (void)addButtonWithIcon:(UIImage *)icon;
- (void)removeButtonAtIndex:(NSUInteger)index;
@end
@implementation SideNavigationBar
...
- (id)initWithDelegate:(id<SideNavigationBarDelegate>)aDelegate {
...
[self setDelegate:aDelegate];
[self setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
[self setFrame:CGRectMake(0.0f, 0.0f, 44.0f, [UIScreen mainScreen].bounds.size.height])];
...
}
- (void)addButtonWithIcon:(UIImage *)icon {
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 44.0f, 44.0f)];
UIImageView *iconView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 44.0f, 44.0f)];
[iconView setContentMode:UIViewContentModeScaleAspectFill];
[iconView setImage:icon];
[button addSubview:iconView];
...set the target and action for the button...
[[self buttons] addObject:button];
}
- (void)drawRect:(CGRect)rect { ...draw buttons on view... }
@end
至于缩略图是自定义的表格 View (在本例中为 GridView )。与其自己制作,不如看看这个:https://github.com/AlanQuatermain/AQGridView
关于ios - 自定义导航控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7404299/