0

我必须使用标题视图在导航栏上添加两行不同字体大小的文本。

我尝试了以下代码:

我希望 EREDITOMETRO 用大字体加粗,而 LA SUCCESSIONE A PORTATA DI MANO 用小字体

UILabel * label =[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 480, 44)]; label.backgroundColor =[UIColor clearColor]; 
label.numberOfLines =2; 
label.font =[UIFont boldSystemFontOfSize:9.0f];
label.textColor =[UIColor whiteColor]; 
label.text = @"EREDITOMETRO \n LA SUCCESSIONE A PORTATA DI MANO"; 

self.navigationItem.titleView = label;
4

3 回答 3

2

尝试这个 -

NSString *stringName = @"Welcome Home" ;
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:stringName];
[attrString addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize: 14.0f] range:NSMakeRange(0, 4)];

UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 480, 44)];
label.numberOfLines =0;
label.attributedText = attrString;
self.navigationItem.titleView = label;
于 2015-04-06T11:03:36.380 回答
0
- (void)setTitle:(NSString *)title
{
    [super setTitle:title];
    UILabel *titleView = (UILabel *)self.navigationItem.titleView;
    if (!titleView) {
        titleView = [[UILabel alloc] initWithFrame:CGRectZero];
        titleView.backgroundColor = [UIColor clearColor];
        titleView.font = [UIFont boldSystemFontOfSize:20.0];
        titleView.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
        titleView.numberOfLines = 2;
        titleView.textColor = [UIColor yellowColor]; 
        self.navigationItem.titleView = titleView;
       } 
    }
于 2015-04-06T10:52:27.793 回答
0

您需要制作一个自定义标签并将其传递给这样的导航项

    let label: UILabel = UILabel(frame: CGRectMake(0, 0, 300, 50))
    label.backgroundColor = UIColor.clearColor()
    label.numberOfLines = 2
    label.font = UIFont.boldSystemFontOfSize(14.0)
    label.textAlignment = .Center
    label.textColor = UIColor.whiteColor()
    label.text = "Your Text"
    self.navigationItem.titleView = label
于 2017-05-08T05:37:26.593 回答