도래울

swift NSMutableAttributedString text color 본문

개발/iOS

swift NSMutableAttributedString text color

도래울 2016. 9. 9. 11:07

extension NSMutableAttributedString {

    

    static public func multicolorTextAttribute(fullText : String, colorText : String, fontColor : UIColor, label : UILabel) -> NSMutableAttributedString {

        

        var mutableString = NSMutableAttributedString()

        

        let range = fullText.rangeOfString(colorText)

        let index: Int = fullText.startIndex.distanceTo(range!.startIndex)


        mutableString = NSMutableAttributedString(string: fullText as String, attributes: [NSFontAttributeName:label.font])

        

        mutableString.addAttribute(NSForegroundColorAttributeName, value: fontColor, range: NSRange(location:index,length:colorText.characters.count))

        

        return mutableString

    }

    

}

'개발 > iOS' 카테고리의 다른 글

xcode downloads all version  (0) 2016.09.23
cocoapods 최신버전 업데이트  (0) 2016.09.20
swift wkwebview alert  (0) 2016.09.09
swift url parsing  (0) 2016.09.09
FBSOpenApplicationErrorDomain error 1  (0) 2016.09.06
Comments