UITextView 属性字符串不变
UIText View attributed string does not change
我正在尝试将属性字符串字体设置为 18。这是代码
NSString *str = [NSString stringWithFormat: @"We notice you've been pre-registrated here. Can you please confirm you are from %@?", visitor.company_name];
NSMutableAttributedString * string = [[NSMutableAttributedString alloc] initWithString:str];
NSRange range = [str.lowercaseString rangeOfString:visitor.company_name.lowercaseString];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor lightGrayColor] range:NSMakeRange(0, str.length)];
[string addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Helvetica-Bold" size:18.0] range:range];
self.textView.attributedText = string;
这只会增加公司名称的大小。字符串大小不会改变原始大小。
这条线救了我一命:
[string addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Helvetica" size:18.0] range:NSMakeRange(0, str.length)];
问题出在定义字符串范围的行上。
NSRange range = NSMakeRange(0,string.length);
[string addAttribute:NSForegroundColorAttributeName value:[UIColor lightGrayColor] range:NSMakeRange(0,string.length)];
我正在尝试将属性字符串字体设置为 18。这是代码
NSString *str = [NSString stringWithFormat: @"We notice you've been pre-registrated here. Can you please confirm you are from %@?", visitor.company_name];
NSMutableAttributedString * string = [[NSMutableAttributedString alloc] initWithString:str];
NSRange range = [str.lowercaseString rangeOfString:visitor.company_name.lowercaseString];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor lightGrayColor] range:NSMakeRange(0, str.length)];
[string addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Helvetica-Bold" size:18.0] range:range];
self.textView.attributedText = string;
这只会增加公司名称的大小。字符串大小不会改变原始大小。
这条线救了我一命:
[string addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Helvetica" size:18.0] range:NSMakeRange(0, str.length)];
问题出在定义字符串范围的行上。
NSRange range = NSMakeRange(0,string.length);
[string addAttribute:NSForegroundColorAttributeName value:[UIColor lightGrayColor] range:NSMakeRange(0,string.length)];