【问题标题】:How to format some text as bold within a UILabel? [duplicate]如何在 UILabel 中将某些文本格式化为粗体? [复制]
【发布时间】:2015-08-29 15:31:45
【问题描述】:

我有一个 iOS UILabel,它需要一些文本是正常的,一些文本是粗体的。粗体文本实际上应该是指向应用程序另一部分的链接,但现在,我只是对点击整个标签做出反应。如何将某些文本格式化为粗体?

【问题讨论】:

    标签: ios uilabel


    【解决方案1】:

    您需要使用 NSAttributedString。请查看此答案以查看示例:Any way to bold part of a NSString?

    【讨论】:

      【解决方案2】:

      使用attributedText 属性:

      NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:@"This is a test."];
      [text addAttribute:NSFontAttributeName
                value:[UIFont boldSystemFontOfSize:12]
                range:NSMakeRange(0, 4)];
      label.attributedText = text;
      

      【讨论】:

        猜你喜欢
        • 2014-09-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-12-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多