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?
There is no such thing as NSColor in iOS. UIColor is what you should use.
NSColor only exists as a OSX class.
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?
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.
© 2022 - 2024 — McMap. All rights reserved.
NSColor
is an OSX class.UIColor
is an iOS class. – Harsho