尝试加粗NSString的开始部分。使用下面提到的代码。

-(void)setText {

    NSString *strEmail = @"Email: [email protected]";
    NSMutableAttributedString *attributedEmail = [[NSMutableAttributedString alloc]initWithString:strEmail];
    NSString *boldFontName = [[UIFont fontWithName:_fontMyriadBold size:20] fontName];
    NSRange boldedRange = NSMakeRange(0, 5);
    [attributedEmail beginEditing];
    [attributedEmail addAttribute:NSFontAttributeName
                   value:boldFontName
                   range:boldedRange];

    [attributedEmail endEditing];

    lblEmailAddress.attributedText = attributedEmail;
}

它没有任何改变。为什么这样,问题是没有得到警告或错误。
请指导。
提前致谢。

最佳答案

检查一下。

NSString * strEmail = @"Email: [email protected]";
NSMutableAttributedString * attributedEmail = [[NSMutableAttributedString alloc] initWithAttributedString:strEmail];
NSRange boldedRange = NSMakeRange(0, 5);
[attributedEmail addAttribute: NSFontAttributeName value:[UIFont fontWithName:_fontMyriadBold size:20] range:boldedRange];
[attributedEmail addAttribute: NSForegroundColorAttributeName value: [*UICOLOR*] range:boldedRange]; // if needed
[lblEmailAddress setAttributedText: attributedEmail];

关于ios - NSMutableAttributedString无法正常工作:将NSString的部分加粗,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19811117/

10-12 04:55