- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有 UITextView,我想将它的行高设置为 50.0f,所以我正在使用 typingAttributes,但没有任何效果,我的代码在 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;
文本不受设置 typingAttributes 的影响,我尝试使用 typingAttributes 更改颜色和字体但没有任何效果
我已经阅读了所有堆栈答案和文档
我做错了什么:(
更新:我什至试过
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
是针对文本域的编辑模式。
typingAttributes
The attributes to apply to new text being entered by the user.
... If the text field is not in editing mode, this property contains the value nil. Similarly, you cannot assign a value to this property unless the text field is currently in editing mode.
相反,您应该分配 attributedText
而不是 text
属性。指定属性的机制是通过您分配的 NSAttributedString
。
关于ios - UITextview typingAttributes 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18817651/
在 macOS 上的 Swift 中,我有以下 TextView 并想设置输入到其中的文本的字体大小,如下所示: myTextView.typingAttributes = ["Unknown" :
我有 UITextView,我想将它的行高设置为 50.0f,所以我正在使用 typingAttributes,但没有任何效果,我的代码在 ViewDidAppear 方法中是这样的 UITextVi
我有一个 TextView ,其中填充了一些蓝色的默认文本,现在我的目标是,无论我在文本中进行什么编辑,它都应该显示为红色。我正在使用 texView.typingAttributes 来实现这个并且
我使用 typingAttributes 设置新字体。在 iOS 10 上,一切正常,但在 iOS 11 上,第一个输入的字符是正确的,但随后属性被重置为以前的,第二个字符被输入以前的字体。这是一个错
我正在尝试将 UITextfield 中键入的文本颜色更改为白色。我使用了以下代码,该代码有效但不会将第一个字母的颜色更改为白色。请参阅随附的屏幕截图。 如何使第一个字母的颜色也变为白色? 我搜索了很
我正在使用 UITextView 输入一些富文本。我创建了一个按钮来更改段落对齐方式(左、中、右)。 当用户选择一些文本并且它按预期工作时,我将对齐应用于 attributedText。 但是,当用户
我正在使用以下方法在 Swift 3 中将我的 textView.typingAttributes 前景色设置为红色。 textView.typingAttributes[NSForegroundCo
我正在尝试在我的应用中创建一个 RichTextEditor。 用户在编辑时可以同时更改前景色和背景色。 这是我设置 typingAttributes 的方法: func textView(_ tex
这个问题在这里已经有了答案: Swift 4 attributedString get typing attributes (3 个答案) 关闭 5 年前。 我曾经能够生成 NSAttributed
我是一名优秀的程序员,十分优秀!