navigation右侧添加多个按钮(三种方法)


方法一:

    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
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值