1. rightBarButtonItem的创建
-(void)initRightBar{ UIBarButtonItem *done =[UIBarButtonItem rightItemWithText:@"新建优惠" withTextColor:[UIColor nvColorWithf63] target:self action:@selector(gotoCreateCoupon)]; self.navigationItem.rightBarButtonItem = done; }
2. 使用UIButton创建UIBarButtonItem
- (UIBarButtonItem *)creatCouponButtonItem { UIButton *creatCouponButton = [[UIButton alloc] initWithFrame:CGRectMake(, , , )]; [creatCouponButton setTitle:@"新建优惠" forState:UIControlStateNormal]; [creatCouponButton setTitleColor:[UIColor nvColorWithf63] forState:UIControlStateNormal]; creatCouponButton.titleLabel.font = [UIFont nvFontWithSize14]; [creatCouponButton addTarget:self action:@selector(gotoCreateCoupon) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithCustomView:creatCouponButton]; return buttonItem; }