![](/img/trans.png)
[英]Bold part of the text in UITextView in Swift using NSMutableAttributedString
[英]NSMutableAttributedString not working: bold the part of NSString
尝试加粗NSString的开始部分。 使用下面提到的代码。
-(void)setText {
NSString *strEmail = @"Email: HR_Contact@sre.com";
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: HR_Contact@sre.com";
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];
您在哪里设置此属性字符串? 也许在-init
之一中? 也许lblEmailAddress
仍为零,您正在尝试设置它。 如果是这样,这就是它对您不起作用的原因。 如果我正确理解lblEmailAddress
来自* .xib。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.