iOS use of NSColor versus UIColor?

大兔子大兔子 提交于 2019-12-10 02:27:20

问题


What's the difference between UIColor and NSColor, and when would one use each? I came across NSColor while trying to figure out UIColor uses for attributed strings in iOS. I understand the use of UIColor for the UIKit and such, but I don't think NSColor is really useful for this kind of thing. Has NSColor fallen into disuse with regards to iOS programming?


回答1:


There is no such thing as NSColor in iOS. UIColor is what you should use.

NSColor only exists as a OSX class.




回答2:


As Nate says, NSColor is OSX only. If you ran across a mention of it in the docs on NSAttributedString, it's probably documentation intended for Mac OS. Some of the docs do "bleed over" between platforms.

If you search the Xcode docs for NSAttributedString(NSStringDrawing) you'll see some UIKit additions to NSAttributedString that let you specify colors using UIColors.

It looks like the equivalent OS X application kit extensions are called NSAttributedString(NSAttributedStringKitAdditions). Gotta love the consistent naming conventions, huh?




回答3:


NSColor is from AppKit and UIColor is from UIKit. UIKit was built from the ground up for iOS and AppKit came over from NeXT. As AppKit is a Mac only framework you cannot use NSColor in an iOS app.



来源:https://stackoverflow.com/questions/23924025/ios-use-of-nscolor-versus-uicolor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!