tags:

views:

64

answers:

2

I am an experienced iPhone dev beginning to work on my first Mac app. One thing that is really throwing me off is the differences between UIView and NSView. It seems that I cannot set the background color of a NSView via interface builder as I can with a UIView. It also seems that I cannot do it by simply sending a setBackgroundColor: message to it. All the examples I have seen are overriding drawRect: in a subclass of NSView. Is that really the only way to do it? What is the conceptual difference here, and why is it this way? NOTE: I am only trying to set the background color to the default grey.

+3  A: 
Alex
I see. Just wanted to make sure I wasn't missing something. thanks!
Joe Cannatti
+6  A: 

Re: Alex's answer:

It's not just that it's older; or rather;… It isn't that it's older. The fact of the matter is that UIKit is simpler. UIView is a much less general construct than NSView; the general method that Apple is pushing for content-rich applications on the iPhone is using OpenGL or Core Animation, relegating UIView, by and large, to simple container stuff. In this context, setBackgroundColor: is useful.

On the Mac, on the other hand, NSView is a highly generic interface element, and for most uses, setBackgroundColor: would just be plain unnecessary. 9 out of 10 times, if you're on a Mac and changing the background color this is either because you are preparing to do your own drawing of user interface elements, or you are doing something that is most likely not condoned by the AHIG.

In summary:

There is no way apart from subclassing it. (NSView is made for subclassing, UIView is made for drop-in-and-use.)

Williham Totland