【问题标题】:UIText View attributed string does not changeUITextView 属性字符串不会改变
【发布时间】:2016-07-04 10:07:40
【问题描述】:

我正在尝试将属性字符串字体设置为 18。这是代码

NSString *str = [NSString stringWithFormat:@"我们注意到你已经在这里预注册了。你能确认你来自%@吗?", 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;

这只会增加公司名称的大小。字符串大小不会从原始大小改变。

【问题讨论】:

    标签: ios objective-c text ios7 uitextview


    【解决方案1】:

    这条线救了我的命:

    [string addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Helvetica" size:18.0] range:NSMakeRange(0, str.length)];
    

    【讨论】:

      【解决方案2】:

      问题在于定义字符串范围的行。

      NSRange range = NSMakeRange(0,string.length);
      [string addAttribute:NSForegroundColorAttributeName value:[UIColor lightGrayColor] range:NSMakeRange(0,string.length)];
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-11-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-09-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多