命令在swift 3.0

时间:2016-08-16 21:36:42

标签: ios swift

我正在尝试将af的contribString实现到UILabel中,但我一直在跟踪错误。 Command failed due to signal: Segmentation fault 11。我正在使用xcode 8 beta和swift 3.0。

    let attributedString = NSMutableAttributedString(string: titleText, attributes: [NSFontAttributeName:UIFont(name: "Avenir-Book", size: 14)])

    let boldFontAttribute = [NSFontAttributeName: UIFont(name: "Avenir-Medium ", size: 14)]

    // Part of string to be bold
    attributedString.addAttributes(boldFontAttribute, range: titleText.rangeOfString("Anytime. Anywhere."))



    introTextLabel.attributedText = attributedString

1 个答案:

答案 0 :(得分:1)

作为我对您原始帖子的评论的后续跟进,这对我有用(titleText是一个快捷的字符串):

let attributedString = NSMutableAttributedString(string: titleText, attributes: [NSFontAttributeName: UIFont(name: "Avenir-Book", size: 14)!])

let boldFontAttribute = [NSFontAttributeName: UIFont(name: "Avenir-Medium", size: 14)!]

// Part of string to be bold
attributedString.addAttributes(boldFontAttribute, range: (titleText as NSString).range(of: "Anytime. Anywhere."))

introTextLabel.attributedText = attributedString