你如何使用 NSAttributedString? - How do you use NSAttributedString?

问题:

Multiple colours in an NSString or NSMutableStrings are not possible. NSStringNSMutableStrings中的多种颜色是不可能的。 So I've heard a little about the NSAttributedString which was introduced with the iPad SDK 3.2 (or around 3.2) and is available on the iPhone as of iPhone SDK 4.0 beta .所以我听说了一些关于NSAttributedString ,它是随iPad SDK 3.2 (或大约 3.2)引入的,并且从iPhone SDK 4.0 beta开始在 iPhone 上可用。

I would like to have a string that has three colours.我想要一根有三种颜色的绳子。

The reason I don't use 3 separate NSStrings, is because the length of each of the three NSAttributedString substrings changes often and so I would prefer, not to use any calculations to re-position 3 separate NSString objects.我不使用 3 个单独的 NSStrings 的原因是因为三个NSAttributedString子字符串中的每一个的长度经常变化,所以我宁愿不使用任何计算来重新定位 3 个单独的NSString对象。

If it's possible using NSAttributedString how do I make the following - (if not possible with NSAttributed string how would you do it):如果可以使用NSAttributedString ,我该如何进行以下操作 - (如果使用 NSAttributed 字符串无法实现,您会怎么做):

替代文字

Edit: Remember, @"first" , @"second" and @"third" will be replaced by other strings at any time.编辑:请记住, @"first"@"second"@"third"将随时被其他字符串替换。 So using hardcoded NSRange values won't work.所以使用硬编码的 NSRange 值是行不通的。


解决方案:

参考一: https://en.stackoom.com/question/Ebus
参考二: https://stackoom.com/question/Ebus
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章