Bold & Non-Bold Text In A Single UILabel?

后端 未结 14 2181
别那么骄傲
别那么骄傲 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)];
    

提交回复
热议问题