navigation右侧添加多个按钮(三种方法)
来源:互联网 发布:7u分享网络电脑版注册 编辑:程序博客网 时间:2024/06/05 09:40
方法一:
UIToolbar* tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 100, 40)]; [tools setBarTintColor:[UIColor whiteColor]]; NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:2]; UIBarButtonItem *saveButton = [[UIBarButtonItem alloc]initWithTitle:@"保存" style:UITabBarSystemItemContacts target:self action:@selector(save:)]; UIBarButtonItem *pulishButton = [[UIBarButtonItem alloc]initWithTitle:@"发布" style:UITabBarSystemItemContacts target:self action:@selector(pulish:)]; [pulishButton setTintColor:kMainColor]; [buttons addObject:saveButton]; [buttons addObject:pulishButton]; [tools setItems:buttons animated:NO]; UIBarButtonItem *myBtn = [[UIBarButtonItem alloc] initWithCustomView:tools]; self.navigationItem.rightBarButtonItem = myBtn;
方法二:
UIBarButtonItem *pulishButton = [[UIBarButtonItem alloc]initWithTitle:@"发布" style:UITabBarSystemItemContacts target:self action:@selector(pulish:)]; [pulishButton setTintColor:kMainColor]; UIBarButtonItem *saveButton = [[UIBarButtonItem alloc]initWithTitle:@"保存" style:UITabBarSystemItemContacts target:self action:@selector(save:)]; [self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects: pulishButton,saveButton,nil]];
方法三:
UIButton *pulishButton=[UIButton buttonWithType:(UIButtonTypeCustom)]; [pulishButton setTitle:@"发布" forState:(UIControlStateNormal)]; [pulishButton setTitleColor:kWenZiColor forState:(UIControlStateNormal)]; pulishButton.layer.masksToBounds=YES; pulishButton.layer.cornerRadius=3; pulishButton.titleLabel.font=[UIFont systemFontOfSize:15]; pulishButton.backgroundColor=[UIColor cyanColor]; [pulishButton addTarget:self action:@selector(pulish:) forControlEvents:UIControlEventTouchUpInside]; UIButton *saveButton=[UIButton buttonWithType:(UIButtonTypeCustom)]; [saveButton setTitle:@"保存" forState:(UIControlStateNormal)]; [saveButton setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)]; saveButton.layer.masksToBounds=YES; saveButton.layer.cornerRadius=3; saveButton.titleLabel.font=[UIFont systemFontOfSize:15]; saveButton.backgroundColor=kMainColor; [saveButton addTarget:self action:@selector(save:) forControlEvents:UIControlEventTouchUpInside]; pulishButton.frame = CGRectMake(0, 0, 50, 30); saveButton.frame=CGRectMake(0, 0, 50, 30); UIBarButtonItem *pulish = [[UIBarButtonItem alloc] initWithCustomView:pulishButton]; UIBarButtonItem *save = [[UIBarButtonItem alloc] initWithCustomView:saveButton]; [self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects: pulish, save,nil]];
个人认为 方法三最好= = 三种方法供大家参考 如果有更好的 欢迎补充与分享哦= =
1 0
- navigation右侧添加多个按钮(三种方法)
- navigation右侧添加多个按钮(三种方法)
- navigationItem.rightBarButtonItem 实现多个右侧按钮
- navigationItem.rightBarButtonItem 实现多个右侧按钮
- tableBar 添加多个按钮的方法
- androidstudio添加多个按钮方法
- 为navigation drawer添加多个fragment
- UITableViewCell左右侧滑动出现多个按钮
- navigation中左滑pop的三种方法
- Android开发---为按钮添加事件的三种方法
- Android开发---为按钮添加事件的三种方法
- Android开发---为按钮添加事件的三种方法
- android为按钮添加事件的三种方法
- android为按钮添加事件的三种方法
- Android开发---为按钮添加事件的三种方法
- Android开发---为按钮添加事件的三种方法
- AutoCAD二次开发三种添加插件按钮的方法之一
- android studio 添加按钮点击事件的三种方法
- Java并发编程:深入剖析ThreadLocal
- 深入理解C语言的define和内联函数
- redis常用数据机构及操作整理
- [Java配置]OS X 更改当前使用的Java的版本
- RBTree
- navigation右侧添加多个按钮(三种方法)
- Code::Blocks配置GTK+2和GTK+3
- grep是什么?怎么用?
- Java 中 float 与 double 的区别
- Redis和Memcached的区别(4)redis内存k/v管理
- js调用servlet写相对路径
- 根据节点遍历树——Oracle个人学习
- IOS开发之记录用户登陆状态
- android html唤醒APP(原生)