【发布时间】:2016-07-04 01:11:34
【问题描述】:
我尝试在 UITextView 中更改字体大小,每次更改属性文本时都会恢复为默认值。
用这个我把中间的测试加粗:
str = [[NSMutableAttributedString alloc] initWithAttributedString:string];
[str addAttribute:NSFontAttributeName value:newFont range:NSMakeRange(range.location, range.length)];
before:中间是粗体。
之后:所有文字加粗
我希望在大小改变后加粗的留在原地。
编辑:
我尝试了这两种方法:
1)
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:currentTextViewEdit.text];
[attributedString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:textSize] range:NSMakeRange(0, currentTextViewEdit.text.length)];
currentTextViewEdit.attributedText = attributedString;
2)
currentTextViewEdit.font = [UIFont fontWithName:currentTextViewEdit.font.fontName size:textSize];
【问题讨论】:
-
如何更改字体大小?
-
currentTextViewEdit.font = [UIFont fontWithName:currentTextViewEdit.font.fontName size:textSize];
-
未测试,但:pastebin.com/wFGhK5W1?
-
如果可行,您能否验证我的回答,以帮助有相同问题的人清楚地看到解决方案而不是发表评论?
-
你明白了(-:谢谢
标签: objective-c uitextview nsattributedstring