iOS use of NSColor versus UIColor?
Asked Answered
T

3

14

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?

Tasso answered 29/5, 2014 at 0:38 Comment(3)
NSColor is an OSX class. UIColor is an iOS class.Harsho
Why is everybody down-voting this question? The docs don't always make it clear when they are referring to OSX vs iOS, and it's very confusing, especially to an iOS novice. I've been doing iOS and Mac OS for years, and still sometimes get confused with docs that cover both Mac OS and iOS. I think this is a legitimate questionApogee
@DuncanC Very true. Mac Docs sometimes cover iOS programming guides as well.Sped
L
18

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

NSColor only exists as a OSX class.

Lowelllowenstein answered 29/5, 2014 at 0:40 Comment(0)
A
8

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?

Apogee answered 29/5, 2014 at 0:54 Comment(0)
Y
4

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.

Yod answered 29/5, 2014 at 0:48 Comment(1)
But can I use UIColor in MacOS app?Dulcle

© 2022 - 2024 — McMap. All rights reserved.