ios7 font size change when create nsattributedstring from html

后端 未结 5 587
醉梦人生
醉梦人生 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:29

    I also faced this issue, I fixed it by iterating to the attributes and reseting the old font size as follows

    NSMutableAttributedString *res = [attributedText mutableCopy];
    [res beginEditing];
    [res enumerateAttribute:NSFontAttributeName
                    inRange:NSMakeRange(0, res.length)
                    options:0
                 usingBlock:^(id value, NSRange range, BOOL *stop) {
                     if (value) {
                         UIFont *oldFont = (UIFont *)value;
                         UIFont *newFont = [oldFont fontWithSize:15];
                         [res addAttribute:NSFontAttributeName value:newFont range:range];
                     }
                 }];
    [res endEditing];
    [self.textFileInputView setAttributedText:res];
    

提交回复
热议问题