//分享按钮
- (void)createRightBtnsAtNavBar{
self.shareBtn = [UIButton buttonWithType:UIButtonTypeCustom];
self.shareBtn.frame = CGRectMake(0, 0, 44.0f, 44.0f);
[self.shareBtn setImage:[UIImage imageNamed:@"share_btn"] forState:UIControlStateNormal];
[self.shareBtn addTarget:self action:@selector(onShareBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *shareItem = [[UIBarButtonItem alloc] initWithCustomView:self.shareBtn];
self.ruleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
self.ruleBtn.frame = CGRectMake(0, 0, 44, 44);
[self.ruleBtn setTitle:@"规则" forState:UIControlStateNormal];
[self.ruleBtn setTintColor:[UIColor redColor]];
[self.ruleBtn addTarget:self action:@selector(onRuleBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *ruleItem = [[UIBarButtonItem alloc] initWithCustomView:self.ruleBtn];
self.navigationItem.rightBarButtonItems = @[shareItem, ruleItem];
}
这样写的话,规则的按钮能加上去,事件也能响应,但是规则两个字死活显示不出来,所以要改变添加方式如下:
//分享按钮
- (void)createRightBtnsAtNavBar{
self.shareBtn = [UIButton buttonWithType:UIButtonTypeCustom];
self.shareBtn.frame = CGRectMake(0, 0, 44.0f, 44.0f);
[self.shareBtn setImage:[UIImage imageNamed:@"share_btn"] forState:UIControlStateNormal];
[self.shareBtn addTarget:self action:@selector(onShareBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *shareItem = [[UIBarButtonItem alloc] initWithCustomView:self.shareBtn];
UIBarButtonItem *ruleItem = [[UIBarButtonItem alloc] initWithTitle:@"规则" style:UIBarButtonItemStylePlain target:self action:@selector(onRuleBtnClicked:)];
ruleItem.tintColor = [UIColor blackColor];
self.navigationItem.rightBarButtonItems = @[shareItem, ruleItem];
}
这样2句代码代替了上边6句代码,而且毫无问题,bingo