Bold & Non-Bold Text In A Single UILabel?

后端 未结 14 2195
别那么骄傲
别那么骄傲 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:48

    Use the below code. I hope it help for you.

    NSString *needToChangeStr=@"BOOK";
    NSString *display_string=[NSString stringWithFormat:@"This is %@",book];
    
    NSMutableAttributedString *attri_str=[[NSMutableAttributedString alloc]initWithString:display_string];
    
    int begin=[display_string length]-[needToChangeStr length];
    int end=[needToChangeStr length];
    
    
    [attri_str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Bold" size:30] range:NSMakeRange(begin, end)];
    
    0 讨论(0)
  • 2020-11-22 09:49

    That's easy to do in Interface Builder:

    1) make UILabel Attributed in Attributes Inspector

    Bold Example Step 1

    2) select part of phrase you want to make bold

    Bold Example Step 2

    3) change its font (or bold typeface of the same font) in font selector

    Bold Example Step 3

    That's all!

    0 讨论(0)
提交回复
热议问题