每个屏幕的 NavigationController 的自定义后退按钮 [英] Custom back button for NavigationController for every screen

查看:19
本文介绍了每个屏幕的 NavigationController 的自定义后退按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试继承 UINavigationController 类来修改背景图像、导航栏大小、后退按钮、标题字体等内容.经过几个小时和大量阅读后,我明白我不应该继承 UINavigationController 类......

I have been trying to subclass the UINavigationController class for modifying things like background image, navigation bar size, back button, tittle font and so on. After a couple of hours and a lot of reading I have understand that I should not subclass the UINavigationController class...

我想要特定的设计并将该设计转移到使用我的自定义 NavigationController 的所有屏幕...

I would like to have specific design and transfer that design to all screens that use my custom NavigationController...

到目前为止,我还没有为此找到任何优雅的解决方案,大多数解决方案都基于配置仅在下一个屏幕(下一个视图)中显示的内容.

SO far I haven't fount any elegant solution for this, most of the solutions are based on configuring something for showing in the next screen only (next view).

我怎样才能做到这一点?也许使用类别?提前致谢.

How can I achieve this? Maybe using categories? Thanks in advance.

推荐答案

我正在展示 UINavigationcontroller 的自定义左栏按钮的代码.您可以在每个视图控制器和两个按钮(右侧和左侧)中添加此代码

I am showing code for custom leftbarbutton of UINavigationcontroller. You can add this code in each view controller and for both button( right and left)

    leftButton = [UIButton buttonWithType:UIButtonTypeCustom];    
    [leftButton setImage:[UIImage imageNamed:@"Yourcutomeimage.png"] forState:UIControlStateNormal];    
    leftButton.frame = CGRectMake(0, 0, 30, 30);
    [leftButton addTarget:self action:@selector(youraction:) forControlEvents:UIControlEventTouchUpInside];  

    self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:leftButton]autorelease];

//或

self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:leftButton]autorelease];

希望能帮到你..

这篇关于每个屏幕的 NavigationController 的自定义后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆