Swift 4 Label attributes

前端 未结 7 701
死守一世寂寞
死守一世寂寞 2020-12-31 09:14

I\'m moving from swift 3 to swift 4. I have UILabels that I am giving very specific text properties to the label. I\'m getting an \'unexpectedly found nil while unwrapping

7条回答
  •  一生所求
    2020-12-31 09:52

    if you want to change particular string value so that below answer is helpful you:-

    let subStr = "Hello" let allStr = "Hello World"

        let newStr = NSMutableAttributedString(string: allStr)
        newStr.addAttribute(kCTFontAttributeName as NSAttributedStringKey, value:  UIFont.init(customFont: .MyriadPro_R, withSize: 18)!, range: (allStr as NSString).range(of: subStr))
        newStr.addAttribute(NSAttributedStringKey.foregroundColor, value: UIColor.PrimaryColor, range: (allStr as NSString).range(of: subStr))
        self.stateLbl.attributedText = newStr
    

提交回复
热议问题