我有 UITextView,我想将其行高设置为 50.0f,所以我使用打字属性,但没有任何效果,我的代码在 ViewDidAppear 方法中像这样
UITextView *textView = [[UITextView alloc]initWithFrame:CGRectMake(0, 0, 300, 300)];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.minimumLineHeight = 50.0f;
paragraphStyle.lineHeightMultiple = 50.0f;
paragraphStyle.maximumLineHeight = 50.0f;
NSDictionary *textViewAttributeDic = [NSDictionary dictionaryWithObject:paragraphStyle forKey:NSParagraphStyleAttributeName];
textView.typingAttributes = textViewAttributeDic;
文本不受设置打字属性的影响,我尝试使用打字属性更改颜色和字体但没有任何作用
我已阅读所有堆栈答案和文档
我做错了什么:(
update:我什至尝试过
UITextView *textView = [[UITextView alloc]initWithFrame:CGRectMake(0, 0, 300, 300)];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.minimumLineHeight = 50.0f;
paragraphStyle.lineHeightMultiple = 50.0f;
paragraphStyle.maximumLineHeight = 50.0f;
NSDictionary *textViewAttributeDic = [NSDictionary dictionaryWithObject:paragraphStyle forKey:NSParagraphStyleAttributeName];
textView.attributedText = [[NSAttributedString alloc] initWithString:@"" attributes:textViewAttributeDic];
当我尝试时
textView.attributedText = [[NSAttributedString alloc] initWithString:@"blahblah" attributes:textViewAttributeDic];
它有效,但我需要没有空格或“废话”字符的空 textView
该文档明确指出typingAttributes
用于文本字段的编辑模式。
打字属性
应用于用户输入的新文本的属性。
...
如果文本字段未处于编辑模式,则此属性包含值 nil。同样,除非文本字段当前处于编辑模式,否则您无法为此属性分配值。
相反,你应该分配attributedText
而不是text
财产。指定属性的机制是通过NSAttributedString
您分配的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)