gpt4 book ai didi

ios - UITextview typingAttributes 不起作用

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:53:18 25 4
gpt4 key购买 nike

我有 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com