Fleija
Fleija

Reputation: 300

iOS use of NSColor versus UIColor?

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?

Upvotes: 14

Views: 5266

Answers (3)

Duncan C
Duncan C

Reputation: 131461

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?

Upvotes: 8

drewdahl
drewdahl

Reputation: 194

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.

Upvotes: 4

Nate Lee
Nate Lee

Reputation: 2842

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

NSColor only exists as a OSX class.

Upvotes: 18

Related Questions