IOS UINavigationItem添加多按钮
来源:互联网 发布:北京银行网银mac版 编辑:程序博客网 时间:2024/05/02 04:40
虽说不难,但查资料还是花了点时间,这里记录一下
方法1
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:2]; UIBarButtonItem *negativeSeperator = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]; negativeSeperator.width = -16; // 修改到边界的距离 [buttons addObject:negativeSeperator]; UIBarButtonItem *categoryButton = [[UIBarButtonItem alloc] initWithImage:VSD_LOCAL_IMAGE(@"icon-category") style:UIBarButtonItemStylePlain target:self action:@selector(categoryButtonClicked:)]; [categoryButton setTintColor:[UIColor colorWithRed:0.25f green:0.25f blue:0.25f alpha:1.0f]]; [buttons addObject:categoryButton]; [buttons addObject:self.navigationItem.leftBarButtonItem]; UIToolbar* tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 100, 45)]; tools.clipsToBounds = YES; // 去除UIToolbar上方边框线 [tools setTintColor:[self.navigationController.navigationBar tintColor]]; [tools setAlpha:[self.navigationController.navigationBar alpha]]; [tools setItems:buttons animated:NO]; UIBarButtonItem *left = [[UIBarButtonItem alloc] initWithCustomView:tools]; self.navigationItem.leftBarButtonItem = left;
优点是自由灵活,就是代码太繁琐
方法2
UIBarButtonItem *categoryButton = [[UIBarButtonItem alloc] initWithImage:VSD_LOCAL_IMAGE(@"icon-category") style:UIBarButtonItemStylePlain target:self action:@selector(categoryButtonClicked:)]; [categoryButton setTintColor:[UIColor colorWithRed:0.25f green:0.25f blue:0.25f alpha:1.0f]]; self.navigationItem.leftBarButtonItems=[[NSArray alloc] initWithObjects:categoryButton, self.navigationItem.leftBarButtonItem, nil];
用的系统方法,代码简洁
0 0
- IOS UINavigationItem添加多按钮
- UINavigationItem添加UISegmentControl
- 添加 UINavigationBar 和 UINavigationItem
- UINavigationItem返回按钮自定义设置
- iOS小技巧-UINavigationItem代码设置导航栏返回按钮的字体
- ios导航栏添加多个按钮
- ios----导航栏添加多个按钮
- iOS 动态添加按钮
- iOS UI NavigationController UINavigationBar UINavigationItem
- UINavigationItem
- UINavigationItem
- ios导航条添加按钮
- ios导航条添加按钮
- iOS开发:动态添加按钮
- IOS AlertView动态添加按钮
- iOS开发:动态添加按钮
- iOS--- UITableView 底部添加按钮
- iOS添加左右导航按钮
- Launch screen interface file base name 对导航栏和标签栏适配的作用
- MFC中CSkinImage显示PNG图片,包括大图中含有一串小图(网狐)
- JAVA注释&标识符&关键字
- Unity3D游戏开发创建桌面快捷方式
- code vs 草地排水
- IOS UINavigationItem添加多按钮
- 60. Permutation Sequence
- 关于android:launchMode=“singleInstance”
- Java笔记2:Eclipse编写第一个Java程序
- View工作原理(一)事件传递原理详解
- 有序表中找对应值算法
- 关于SVN常用命令之import
- 给定两点坐标,添加轨迹
- Intent.ACTION_VIEW无法调用短信页面