swift label不同颜色、不同字体

let string = "点击注册按钮,即表示您已同意隐私条款和服务协议"

        

        let ranStr = "同意"

        

        let attrstring:NSMutableAttributedString = NSMutableAttributedString(string:string)

        

        let str = NSString(string: string)

        

        let theRange = str.range(of: ranStr)

        

        attrstring.addAttribute(NSForegroundColorAttributeName, value: UIColor.red, range: theRange)

        

        attrstring.addAttribute(NSFontAttributeName, value: UIFont.systemFont(ofSize: 14), range: theRange)

        

        

        label.attributedText = attrstring

posted @ 2016-08-12 17:11  zuidap  阅读(5885)  评论(0编辑  收藏  举报