bold part of string in UITextView swift

前端 未结 4 1387
心在旅途
心在旅途 2020-12-14 09:15

Here is the text:

@IBOutlet weak var legalText: UITextView!
let textToAppend = \"TERMS OF SERVICE\\nLast Updated: May 7, 2015\\n\\nPLEASE NOTE: The HIGO Term         


        
4条回答
  •  鱼传尺愫
    2020-12-14 09:24

    Swift 3 Update (from the answer of @Hamza Ansari)

    func attributedText()-> NSAttributedString
    {
        let string = "TERMS OF SERVICE\nLast Updated: May 7, 2015\n\nPLEASE NOTE: The HIGO Terms of Service as stated below is effective as of the 'Last Updated' date above for any user who is browsing the HIGO website, or for any user who creates a HIGO account on or after that date." as NSString
    
        let attributedString = NSMutableAttributedString(string: string as String, attributes: [NSFontAttributeName:UIFont.systemFont(ofSize: 15.0)])
    
        let boldFontAttribute = [NSFontAttributeName: UIFont.boldSystemFont(ofSize: 15.0)]
    
        // Part of string to be bold
        attributedString.addAttributes(boldFontAttribute, range: string.range(of: "TERMS OF SERVICE"))
        attributedString.addAttributes(boldFontAttribute, range: string.range(of: "PLEASE NOTE:"))
    
        // 4
        return attributedString
    }
    

提交回复
热议问题