2012-11-15 54 views
9

我发现6之前版本的iOS版本的NSAttributedString的可用性信息存在冲突。如果向后兼容,它会非常有用。NSAttributedString在iOS 6之前是否可用?

这说,这是可以作为的iOS 4: Why No NSAttributedString on the iPhone?

在苹果网站,它说的iOS 6及更高版本:https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSAttributedString_Class/Reference/Reference.html

我试图实现它在我的代码如下所示:

NSAttributedString *commentString = [[NSAttributedString alloc] initWithString:@"I really love raisins" attributes:@{NSForegroundColorAttributeName: [UIColor blackColor]}]; 

它适用于iOS 6,但不是当我尝试在iOS 5或iOS 5.1中运行它时。我没有测试过早期版本。

我只是想使用未包含在旧版本中的功能?

回答

14

从iOS3.2开始就已经有了。但是,在某些UI控件(如UILabel,UIButton,UITextView等)中使用它们的功能仅在iOS6以后才可用。你仍然可以使用它们使用CoreText的< 6.0。

6

NSAttributeStringinitWithString:attributes:方法已经出现。在iOS 4.0中添加了一些NSAttributedString的方法。在iOS 6.0中添加了作为UIKit类别添加的所有方法。

与此行中的问题:

NSAttributedString *commentString = [[NSAttributedString alloc] initWithString:@"I really love raisins" attributes:@{NSForegroundColorAttributeName: [UIColor blackColor]}]; 

是未加入NSForegroundColorAttributeName恒定,直到iOS的6.0。

因此,虽然NSAttributedString已经存在了一段时间,但所有有用的东西直到6.0才加入。

+0

这是两天内两次我们在几秒钟内回答了一个ios问题。礼炮。 – Bergasms

相关问题