ios7 font size change when create nsattributedstring from html

后端 未结 5 592
醉梦人生
醉梦人生 2020-11-29 06:57

I have a UITextView where I\'m managing an NSAttributedString, initially entered as normal via the keyboard. I save the attributed string as HTML, which looks fine. When I

5条回答
  •  天涯浪人
    2020-11-29 07:37

    Swift 3.0 Version

    With 0.75 ratio

    yourAttrStr.beginEditing()
    yourAttrStr.enumerateAttribute(NSFontAttributeName, in: NSMakeRange(0, yourAttrStr.length), options: .init(rawValue: 0)) { 
            (value, range, stop) in
            if let font = value as? UIFont {
                let resizedFont = font.withSize(font.pointSize * 0.75)
                yourAttrStr.addAttribute(NSFontAttributeName, value: resizedFont, range: range)
            }
    }
    yourAttrStr.endEditing()//yourAttrStrwill be the same size as html string
    

提交回复
热议问题