【问题标题】:Getting the attribute dictionaries from a NSAttributedString从 NSAttributedString 获取属性字典
【发布时间】:2013-03-15 18:19:39
【问题描述】:

如何获取 NSAttributedString 的属性?

我想使用enumerateAttributesInRange:NSMakeRange(0, str.length),然后将每个属性保存在 NSMutableDictionaries 中,但我想知道是否存在更好的方法。

编辑------ 我的问题是我有一个NSAttributedString,我想在它的属性上使用这个函数......

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

【问题讨论】:

  • 你真的需要为那个函数提供属性吗?如果您使用相关的属性字符串创建了框架设置器,它应该已经知道如何处理它们,因此您应该能够传入 NULL。

标签: objective-c


【解决方案1】:
 NSDictionary *attributesFromString = [string attributesAtIndex:0 longestEffectiveRange:nil inRange:NSMakeRange(0, string.length)];

【讨论】:

    【解决方案2】:
    UITextView *t = [[UITextView alloc] init];
    [t setAttributedText:a];
    t.typingAttributtes
    

    【讨论】:

      猜你喜欢
      • 2013-11-15
      • 1970-01-01
      • 1970-01-01
      • 2022-12-05
      • 1970-01-01
      • 2017-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多