美文网首页ios
导航栏那些事

导航栏那些事

作者: iOS打怪升级 | 来源:发表于2017-05-18 16:01 被阅读226次

1.自定义返回按钮的问题

通过设置当前页面的leftBarButtonItem 来替换系统自带的back 按钮,下面是系统UINavigationBar的头文件部分关于leftBarButtonItem 的阐述
@interface UINavigationBar : UIView <NSCoding, UIBarPositioning> 
/* By default, the leftItemsSupplementBackButton property is NO. In this case,
 the back button is not drawn and the left item or items replace it. If you
 would like the left items to appear in addition to the back button (as opposed to instead of it)
 set leftItemsSupplementBackButton to YES.
 */
@property(nonatomic) BOOL leftItemsSupplementBackButton NS_AVAILABLE_IOS(5_0) __TVOS_PROHIBITED;
// Some navigation items want to display a custom left or right item when they're on top of the stack.
// A custom left item replaces the regular back button unless you set leftItemsSupplementBackButton to YES
@property(nullable, nonatomic,strong) UIBarButtonItem *leftBarButtonItem;
@end

意思:一个自定义的left item 将会替换系统的返回按钮,除非你设置leftItemsSupplementBackButton 属性为Yes ,back 按钮才不会被替换

下面是实现代码:

    [self.navigationItem setLeftBarButtonItem:[[UIBarButtonItem alloc] initWithTitle:@"自定义" style:UIBarButtonItemStylePlain target:self action:@selector(clickEvent:)]];

     或者设置left items 组合按钮,比如在webView 的控制器中使用是需要两个按钮
    UIBarButtonItem * test1 = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(clickEvent:)];
    UIBarButtonItem * test2 = [[UIBarButtonItem alloc] initWithTitle:@"关闭" style:UIBarButtonItemStylePlain target:self action:@selector(clickEvent:)];
    [self.navigationItem setLeftBarButtonItems:@[test1,test2]];

如果想让自己设置的left item 失效,采用系统的back ,采用下面的代码:

 [self.navigationItem setLeftBarButtonItem:nil];

效果如下


自定义返回按钮.gif
自定义left 组合.gif

2.待续。。。

相关文章

  • 导航栏那些事

    1.自定义返回按钮的问题 通过设置当前页面的leftBarButtonItem 来替换系统自带的back 按钮,下...

  • iOS 导航栏上那些事

    一、侧滑返回 侧滑返回手势是从iOS7开始增加的一个返回操作,经历了两年时间估计iPhone用户大部分都已经忽略了...

  • 有关导航栏的那些事

    1、设置导航栏中间的标题: 2、设置导航栏的 标题 文字颜色: 3、设置NavigationBar背景颜色 4、设...

  • iOS导航栏那些事(LargeTitles)

    在我手机里,【AppStore】这款软件打开的频率虽然不是最高的,但是它是我认为做的最好的。它的亮眼之处在我看来有...

  • Swift_ios_开发之UINavigationControl

    Swift_ios_开发之UINavigationController的常用属性那些事 1.导航栏是否隐藏 sel...

  • swift-导航栏

    swift-导航栏直接上代码 导航栏整体背景颜色 导航栏左侧按钮 自定义 导航栏左侧 隐藏 导航栏右侧图片 参考:...

  • iOS 状态栏(statusbar)导航栏(navigation

    导航栏透明 导航栏渐变 状态栏字体颜色改变 导航栏隐藏如果导航栏自定义度高,需要完全自己重写,可以隐藏原来的导航栏...

  • OC_导航栏 + iOS10

    导航栏标题 导航栏

  • 导航栏渐变隐现

    页面不显示导航栏,上托一定的距离显示导航栏. 设置导航栏存在且透明: 1.设置导航栏的透明: //导航栏透明 ...

  • Android隐藏和显示虚拟导航栏

    隐藏导航栏 显示导航栏 沉浸式状态下显示导航栏

网友评论

    本文标题:导航栏那些事

    本文链接:https://www.haomeiwen.com/subject/bcusxxtx.html