2013-03-15 67 views
5

如何獲取NSAttributedString的屬性?從NSAttributedString獲取屬性字典

我以爲使用enumerateAttributesInRange:NSMakeRange(0, str.length),然後將每個屬性保存在NSMutableDictionaries中,但我想知道是否存在更好的方法。

EDIT ------ 我的問題是,我有一個NSAttributedString,我想使用這個功能在它的屬性...

CTFramesetterSuggestFrameSizeWithConstraints(framesetter,range, __ATTRIBUTES__, size , NULL); 
+0

所行此http:/ /stackoverflow.com/questions/6782450/objective-c-change-all-attributes-in-nsattributedstring – 2013-03-15 18:23:38

+1

你真的需要提供該功能的屬性?如果您使用有問題的屬性字符串創建了framesetter,它應該已經知道如何處理它們,所以您應該能夠傳入NULL。 – 2013-03-16 00:06:27

回答

-1
UITextView *t = [[UITextView alloc] init]; 
[t setAttributedText:a]; 
t.typingAttributtes 
0
NSDictionary *attributesFromString = [string attributesAtIndex:0 longestEffectiveRange:nil inRange:NSMakeRange(0, string.length)];