ios - 自定义导航控件

标签 ios ipad

我想使用 Reeder iPad 应用程序使用的一些技术:

http://reederapp.com/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/

相关文章:

ios - 为什么我的 superview-with-subview 在模态呈现时会缩小(使用自动布局)?

ios - 获取所有选定行的文本

iphone - 使用OpenGL-ES的Paint应用程序中的模糊效果(湿润湿效果)

ios - 当我创建一个新的 UIWindow 时,iPad airplay 显示器显示黑屏

ipad - 当模态视图可见且 iPad 旋转时,UIPopover 的内容更改为随机方向

ios - 滚动 tableView 部分页脚和页眉

ios - Flutter ios cloud_firestore 给出错误

ios - 如何在 SwiftUI (iOS) 中处理数据删除而不导致应用程序崩溃

iphone - 应用程序中的帮助菜单

iphone - 推送的 ViewController 是 "greyed out"不能与它保持一致