Swift4 通过普通字符串获取一个富文本字符串

/**获取富文本字符串*/

func getAttributedStringFrom(str: String, strFont: CGFloat = 13.0, strColor: UIColor, str0: String, str0Font: CGFloat = 13.0, str0Color: UIColor) -> NSMutableAttributedString {
    let attriStr = NSMutableAttributedString.init(string: str + str0)
    attriStr.addAttributes([NSAttributedStringKey.font : UIFont.systemFont(ofSize: strFont), NSAttributedStringKey.foregroundColor : strColor], range: NSRange.init(location: 0, length: str.count - 1))
    attriStr.addAttributes([NSAttributedStringKey.font : UIFont.systemFont(ofSize: str0Font), NSAttributedStringKey.foregroundColor : str0Color], range: NSRange.init(location: str.count, length: str0.count))
    return attriStr
}




猜你喜欢

转载自blog.csdn.net/flyingfirefish/article/details/80091255