kmp*_*mp3 9 objective-c ios ios5 ios6
我发现有关6版之前的iOS版本的NSAttributedString可用性的相互矛盾的信息.如果它有点向后兼容,那么它将非常有用.
这里说它从iOS 4开始可用: 为什么iPhone上没有NSAttributedString?
在Apple网站上,它说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]}];
Run Code Online (Sandbox Code Playgroud)
它适用于iOS 6,但是当我尝试在iOS 5或iOS 5.1中运行它时.我没有测试过早期版本.
我只是想尝试使用旧版本中未包含的功能吗?
Edw*_*dar 14
它自iOS3.2以来一直存在.但是,在UILabel,UIButton,UITextView等特定UI控件中使用它们的能力仅在iOS6之后才可用.您仍然可以使用CoreText将其用于<6.0.
NSAttributeStringinitWithString:attributes:根据iOS参考文档,该方法自iOS 3.2以来一直存在.NSAttributedString在iOS 4.0中添加了一些方法.UIKit在iOS 6.0中添加了作为类别添加的所有方法.
这条线的问题:
NSAttributedString *commentString = [[NSAttributedString alloc] initWithString:@"I really love raisins" attributes:@{NSForegroundColorAttributeName: [UIColor blackColor]}];
Run Code Online (Sandbox Code Playgroud)
是NSForegroundColorAttributeNameiOS 6.0之前没有添加常量.
因此,虽然NSAttributedString已经存在了一段时间,但直到6.0才会添加所有有用的东西.
| 归档时间: |
|
| 查看次数: |
6475 次 |
| 最近记录: |