gpt4 book ai didi

ios - 带有 NSAttributedString 和自定义属性的 UITextView 不起作用

转载 作者:可可西里 更新时间:2023-11-01 03:24:32 25 4
gpt4 key购买 nike

使用 UITextView 时,我尝试将自定义属性添加到属性字符串。但是,在分配给 UITextView 的属性文本后,所有自定义键都将丢失。像这样:

NSMutableAttributedString *lString = [[ NSMutableAttributedString alloc ] initWithString: @"astring"
attributes: @{ @"customkey": @"customvalue" }];
NSLog(@"string: %@", lString); // shows customkey present
textView.attributedText = lString;
NSLog(@"result: %@", self.textView.attributedText); // shows customkey missing

这应该有效吗?

最佳答案

从 iOS 7 开始,它现在可以随心所欲地工作了:

来自 Accessing Attributes :

An attributed string identifies attributes by name, storing a value under the attribute name in an NSDictionary object, which is in turn associated with an NSRange that indicates the characters to which the dictionary’s attributes apply. You can assign any attribute name-value pair you wish to a range of characters, in addition to the standard attributes.

它适用于标准和 NSTextStorage (Text Kit) 支持的 UITextViews。

关于ios - 带有 NSAttributedString 和自定义属性的 UITextView 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13648003/

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