美文网首页
navigationItem文字不显示

navigationItem文字不显示

作者: BetterComingDay | 来源:发表于2017-07-18 13:55 被阅读152次
//分享按钮
- (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

相关文章

网友评论

      本文标题:navigationItem文字不显示

      本文链接:https://www.haomeiwen.com/subject/bnfhkxtx.html