你如何使用 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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章