Can I set the `attributedText` property of `UILabel`

后端 未结 8 889
长发绾君心
长发绾君心 2020-12-22 21:52

Can I set the attributedText property of a UILabel object? I tried the below code:

UILabel *label = [[UILabel alloc] init];
label.a         


        
8条回答
  •  离开以前
    2020-12-22 22:23

    for Swift 4:

    iOS 11 and xcode 9.4

      let str = "This is a string which will shortly be modified into AtrributedString"
    
      var attStr = NSMutableAttributedString.init(string: str)
    
      attStr.addAttribute(.font,
                    value: UIFont.init(name: "AppleSDGothicNeo-Bold", size: 15) ?? "font not found",
                    range: NSRange.init(location: 0, length: str.count))
    
      self.textLabel.attributedText = attStr
    

提交回复
热议问题