Bold & Non-Bold Text In A Single UILabel?

后端 未结 14 2493
别那么骄傲
别那么骄傲 2020-11-22 08:51

How would it be possible to include both bold and non-bold text in a uiLabel?

I\'d rather not use a UIWebView.. I\'ve also read this may be possible using NSAttribut

14条回答
  •  旧巷少年郎
    2020-11-22 09:36

    In this case you could try,

    UILabel *displayLabel = [[UILabel alloc] initWithFrame:/*label frame*/];
    displayLabel.font = [UIFont boldSystemFontOfSize:/*bold font size*/];
    
    NSMutableAttributedString *notifyingStr = [[NSMutableAttributedString alloc] initWithString:@"Updated: 2012/10/14 21:59 PM"];
    [notifyingStr beginEditing];
    [notifyingStr addAttribute:NSFontAttributeName
                         value:[UIFont systemFontOfSize:/*normal font size*/]
                         range:NSMakeRange(8,10)/*range of normal string, e.g. 2012/10/14*/];
    [notifyingStr endEditing];
    
    displayLabel.attributedText = notifyingStr; // or [displayLabel setAttributedText: notifyingStr];
    

提交回复
热议问题