在TextView中更改属性文本的文本大小

时间:2016-08-30 12:16:46

标签: ios swift uitextview uifont

在这里我尝试重新绘制文本,因为颜色方案 - 我成功的日/夜,但我没有添加不同的文本大小相同的方式 - 我得到"致命错误:意外发现nil同时打开一个可选值&#34 ;. fontSize不为null,它是一个浮点数,因此它不会崩溃

public static func processAttributedText(text:NSMutableAttributedString?) -> NSMutableAttributedString?{
    var sPref = SharedPreferences()

    if let text = text{
    let textAttributes = [
        NSForegroundColorAttributeName: isNight() ? background_light : background_night
    ]
        let fontSize = sPref.getTextSize()
        let font = UIFont (name: "roboto", size: CGFloat(fontSize))! //Here where the error is
    let fontAttributes = [
        NSFontAttributeName : font
    ]
    text.enumerateAttributesInRange(NSRange(0..<text.length), options: []) { (attributes, range, _) -> Void in
        for (attribute, object) in attributes {
          if let textColor = object as? UIColor{
                if (!textColor.isEqual(Utils.greyColor) && !textColor.isEqual(Utils.redColor)){
                    NSLog("found our attr")
                    text.setAttributes(textAttributes , range: range)
                }                                        
            }
            if  let _ = object as? UIFont {
               text.setAttributes(fontAttributes, range: range)
           }

        }
    }
    }
    return text
}

0 个答案:

没有答案
相关问题