NsMutableAttributed字符串swift

时间:2016-06-02 12:35:02

标签: ios swift nsattributedstring

我正在使用swift中的编辑器应用程序。

对于编辑器,我使用属性字符串,剪切和粘贴文本时出现随机错误。

这是错误:

-[NSBigMutableString characterAtIndex:]: Index 3369 out of bounds; string length 3367'

我将此代码用于属性字符串。

func textView(textView: UITextView, shouldChangeTextInRange range: NSRange, replacementText text: String) -> Bool {

    if (text.characters.count == 0 && range.length == 1) {
        return true
    }
    if !isBold {
       let size = CGFloat(Float(lblFontSize.text!)!)
  let boldFont: UIFont = UIFont(name: "MinwalaNastaleeq-checking", size: size)!
        let boldAttr: [String : AnyObject] = [
            NSFontAttributeName : boldFont,
            NSParagraphStyleAttributeName : titleParagraphStyle,
            NSForegroundColorAttributeName : textColor
        ]
        let attributedText: NSMutableAttributedString = NSMutableAttributedString(string: text, attributes: boldAttr)
       textView.replaceRange(textView.selectedTextRange!, withText: text)
        let textViewText: NSMutableAttributedString = NSMutableAttributedString(attributedString: textView.attributedText)

        textView.attributedText = textViewText
        return false
    }

    return true
}

提前致谢

0 个答案:

没有答案
相关问题