iOS- 11设置导航条(扩展类UIBarButtonItem)
来源:互联网 发布:淘宝卖家给买家的好评 编辑:程序博客网 时间:2024/06/10 04:36
小知识:
1.UIBarButtonItem:描述按钮具体的内容
2.UINavigationItem:设置导航条上的内容(左边,右边,中间)
3.tabBarItem:设置tabBar上的按钮内容(tabBarButton)
左右item
问题:
- UIButton包装成UIBarButtonItem就会导致点击区域扩大
应该包装成UIVIew在进行添加扩展类UIBarButtonItem-代码如下
UIBarButtonItem+ZYExtension.h#import <UIKit/UIKit.h> @interface UIBarButtonItem (ZYExtension) + (instancetype)itemWithNorImage:(NSString *)image highImage:(NSString *)highImage target:(id)target action:(SEL)action; @end
UIBarButtonItem+ZYExtension.m
#import "UIBarButtonItem+ZYExtension.h" @implementation UIBarButtonItem (ZYExtension) + (instancetype)itemWithNorImage:(NSString *)image highImage:(NSString *)highImage target:(id)target action:(SEL)action { UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; [btn setImage:[UIImage imageNamed:image] forState:UIControlStateNormal]; [btn setImage:[UIImage imageNamed:highImage] forSt ate:UIControlStateHighlighted]; [btn sizeToFit]; [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside]; UIView *containVew = [[UIView alloc] initWithFrame:btn.bounds]; [containVew addSubview:btn]; return [[UIBarButtonItem alloc]initWithCustomView:containVew]; }
使用方法:(例如)
self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithNorImage:@"nav_item_game_icon" highImage:@"nav_item_game_click_icon" target:self action:@selector(game)];
设置导航条标题
- 只要通过模型设置,都需要通过付文本设置
- 设置导航条标题
self.navigationItem.title = @"我的"; NSMutableDictionary *attrs = [NSMutableDictionary dictionary]; attrs[NSFontAttributeName] = [UIFont boldSystemFontOfSize:20]; [self.navigationController.navigationBar setTitleTextAttributes:attrs];
- titleVIew
self.navigationItem.titleView = [[UIImageView alloc]initWithImage: [UIImage imageNamed:@"MainTitle"]];
片段代码:(调用)
- (void)setupNavBar { // 左边Item self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithNorImage:@"nav_item_game_icon" highImage:@"nav_item_game_click_icon" target:self action:@selector(game)]; // 右边Item self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithNorImage:@"navigationButtonRandom" highImage:@"navigationButtonRandomClick" target:self action:nil]; // 中间titleView self.navigationItem.titleView = [[UIImageView alloc]initWithImage: [UIImage imageNamed:@"MainTitle"]]; }
- (void)setupNavBar{// 设置UIBarButtonItem *settingItem = [UIBarButtonItem itemWithNorImage:@"mine-setting-icon" highImage:@"mine-setting-icon-click" target:self action:@selector(setting:)];// 夜间模式UIBarButtonItem *nightItem = [UIBarButtonItem itemWithNorImage:@"mine-moon-icon" selImage:@"mine-moon-icon-click" target:self action:@selector(night:)];// 设置self.navigationItem.rightBarButtonItems = @[settingItem,nightItem];// 只要通过模型设置,都需要通过富文本设置// 设置导航条标题 ==> UINavigationBarNSMutableDictionary *attrs = [NSMutableDictionary dictionary]; attrs[NSFontAttributeName] = [UIFont boldSystemFontOfSize:20];[self.navigationController.navigationBar setTitleTextAttributes:attrs]; } #pragma mark- 夜间模式以及设置点击事件- (void)night:(UIButton *)btn{// 选中状态-必须手动btn.selected = !btn.selected;}- (void)setting:(UIButton *)btn{}
阅读全文
0 0
- iOS- 11设置导航条(扩展类UIBarButtonItem)
- 7.30 iOS 5.0中,导航条引入了 在一侧设置多个UIBarbuttonItem方法
- UIBarButtonItem导航条按钮封装
- ios设置导航条背景图片
- iOS---设置导航条文字
- IOS开发(10)UIBarButtonItem导航栏添加按钮
- 定义导航条--UIBarButtonItem
- IOS-9-UIBarButtonItem导航条-添加自定义Left或者Right按钮
- 导航栏颜色及UIBarButtonItem 的设置
- 设置UIBarButtonItem 导航栏返回键
- ios导航条的设置(UINavigati…
- iOS导航条设置为白色
- iOS 开发导航条的透明设置
- iOS navigationcontroller 的导航条的设置
- iOS---导航条的一些设置
- iOS 设置NavgationBar导航条为透明
- iOS 设置导航条的主题
- IOS 导航条的样式设置
- 通过JavaScript代码实现 标题的控制+添加信息
- 机器学习之——自动求导
- win10 磁盘100%
- SpringBoot集成Security(实现自定义表单,自定义验证)
- 国内最火的 HTML、CSS、JavaScript 开源项目 Top 榜,你知多少?
- iOS- 11设置导航条(扩展类UIBarButtonItem)
- yii2 Rbac使用yii命令一键建表
- MyBatis
- 菜鸟的第一博>_<
- BASE64、MD5、SHA1
- QWidget子窗口中setStyleSheet无效,解决方法
- python数据可视化——安装matplotlib
- 文件的下载之fileupload组件
- SpringBoot 使用druid监控数据库