开发者社区 问答 正文

UINavigationBar添加2个UILabel

我有一个自定义UINavigationBar,其中在titleView有两行label:

    UILabel *navBarLabel = [[UILabel alloc] initWithFrame:CGRectZero];  
    UINavigationItem *item = [[UINavigationItem alloc] init];  
    navBarLabel.backgroundColor = [UIColor clearColor];
    navBarLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:14];
    navBarLabel.numberOfLines = 2;
    navBarLabel.textAlignment = UITextAlignmentCenter;
    navBarLabel.textColor = [UIColor colorWithRed:124.0/255.f green:125.0/255.f blue:128.0/255.f alpha:1.0];
    navBarLabel.text = @"This\nis an example";
    [navBarLabel sizeToFit];
    item.titleView = navBarLabel;

在UIlabel文本中,需要添加两个UILabel,其中一个在另一个的顶部,分别在每行实现定制字体。能否实现?

展开
收起
爵霸 2016-03-26 08:23:41 1646 分享 版权
1 条回答
写回答
取消 提交回答
  • 可以试试这样 将这两个UILabel添加至一个新的UIView中 ,然后将UIView 添加至titleView中,如果移除的话 只需要移除这个UIView

    2019-07-17 19:15:04
    赞同 展开评论
问答地址: