3

行の高さを管理するために NSMutableParagraphStyle を使用している段落があります。また、段落内の 1 つの単語の色を変更したいのですが、これは私が使用しているコードですが、1 つの単語の色を変更するだけです (attributedText は上書きされます) どうすれば修正できますか?? 何か助けて??

NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];

paragraphStyle.lineHeightMultiple = 1.45f;

paragraphStyle.alignment = UITextAlignmentRight;

NSDictionary *ats = @{
                      NSFontAttributeName            : [UIFont fontWithName:@"Helvetica"
                                                                      size:currentSize],
                      NSParagraphStyleAttributeName  : paragraphStyle,

                      };


ayaTxt.attributedText    = [[NSAttributedString alloc] initWithString:ayaTxt.text
                                                             attributes:ats];

NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc]
                                         initWithString:ayaTxt.text];

NSRange range = [[AyatWords objectAtIndex:aya] rangeOfString:@":"];

[attrString addAttribute:NSForegroundColorAttributeName
                   value:[UIColor colorWithRed:(25.0/255.0)
                                         green:(168.0/255.0)
                                          blue:(167.0/255.0)
                                         alpha:1.0]
                   range:NSMakeRange(0, range.location + 1)];

ayaTxt.attributedText = attrString;

ありがとう ..

4

1 に答える 1