如何更改字符串中第二个单词的字体大小

How to change font size of a second word in String

我有一个字符串:"Lorem ipsum dolor sit"

我需要更改“ipsum”的字体大小。

任何人都知道如何更改字符串中特定单词的字体大小。

你应该使用 NSAttributedString.

NSMutableAttributedString *myString = [[NSMutableAttributedString alloc] initWithString:@"Lorem ipsum dolor sit"];
[myString addAttribute:NSFontAttributeName value:[UIFont  systemFontOfSize:20.0] range:NSMakeRange(7, 5)];

试试这个:

 NSMutableAttributedString *string = 
                              [[NSMutableAttributedString alloc]
                                        initWithString: @"Lorem ipsum dolor sit"];



[string addAttribute: NSFontAttributeName
                  value:  [UIFont fontWithName:@"Didot" size:24]
                  range: NSMakeRange(7,5)];
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"Lorem ipsum dolor sit"];
[str addAttribute:NSFontAttributeName
              value:[UIFont systemFontOfSize:20.0]
              range:NSMakeRange(7, 5)];