2

I'm new to Xcode (Mac development, not iOS), and for some reason I can't figure out how to even change any object's color (text, background or really anything). Every site seems to say to click on the object, go to the attributes inspector and all of those options are under 'view'. However, in my Xcode (5.1.1) all it shows under 'view' is tag, focus ring, drawing, and auto-resizing. Am I missing something obvious?

Andrew Sula
  • 939
  • 8
  • 24
zigzaugg
  • 61
  • 10
  • What object are you trying to change the color of? It might be helpful to do a quick google search of that object + "change background color." – Jared Price Aug 15 '14 at 19:38
  • labels and buttons. And it's for background as well as text color. Also, I definitely googled it. It came up with what I said, under the view section of the Attributes Inspector. Only, it's not there. – zigzaugg Aug 15 '14 at 19:41
  • @zigzaugg Mac windows tend to have a hierarchy of views. Selecting the object you want from the canvas can be annoying. You get the object's enclosing view instead of the object you want. Use the jump bar, which is above the canvas, to access the object you want. – Swift Dev Journal Aug 15 '14 at 20:21
  • I tried all of the object hierarchies in the jump bar, and none of them had what I was looking for. I believe the selected answer below explains why. Thanks though! – zigzaugg Aug 15 '14 at 20:23

2 Answers2

3

On OS X, NSView does not have an intrinsic backgroundColor property. Thus, you cannot set the color of a view from Interface Builder. You have to create an NSView subclass and override -drawRect: or -updateLayer to make it the color you want. Even then, that color will not show up in Interface Builder. (This changes in Xcode 6, which is still in beta as of this writing.)

Is this somewhat annoying? Yeah. But that's the way it is.

As for changing the text of an object, you should be able to do it from the Attributes inspector, but only if it's something that already has text (i.e. a text field, text view, or button). An arbitrary custom view does not have text, so you can't set it in Interface Builder.

BJ Homer
  • 48,806
  • 11
  • 116
  • 129
  • Wow, that's pretty ridiculous. Glad to hear they plan on fixing it! And thanks for letting me know. And I meant text color, I understand how to change text. – zigzaugg Aug 15 '14 at 20:18
  • hey BJ... as I remember No one missed NSView not doing anything until UIView came around and could actually do things... – Grady Player Aug 15 '14 at 20:53
0

You should easily be able to set the background color of whatever UI element you want programmatically.

[viewObject setBackgroundColor:[UIColor greenColor]];

As for editing a xib for OSX I'm not sure. I have only done iOS development.

Jared Price
  • 5,217
  • 7
  • 44
  • 74
  • I'm viewing MainMenu.xib. And yes, the utilities is open. And as I said in my post, I'm in the attributes inspector. It's just the background and text color things aren't there like everyone says they are. – zigzaugg Aug 15 '14 at 19:46
  • Maybe I don't know what I'm doing then. I was just following instructions from [this](https://developer.apple.com/librarY/mac/referencelibrary/GettingStarted/RoadMapOSX/chapters/01_Introduction.html). And [this](https://developer.apple.com/librarY/mac/referencelibrary/GettingStarted/RoadMapOSX/books/RM_YourFirstApp_Mac/Articles/Introduction.html) which is a part of the tutorial explains everything using the .xib. Is that wrong? – zigzaugg Aug 15 '14 at 19:54
  • 1
    OP asking for OS X, not IOS. – modusCell Aug 15 '14 at 19:55
  • My apologies, I forgot you were developing for Mac. Does XCode not make use of storyboards for Mac development? The code should be similar at least. – Jared Price Aug 15 '14 at 19:56
  • but is there a way to do it without the coding part? I have no problem with that, it's just changing large numbers of colors would be much faster without coding. And as far as I know, it doesn't use story boards. Again, I just started using XCode today. – zigzaugg Aug 15 '14 at 19:56
  • `NSView` does not have a `backgroundColor` property, so naturally it is also not exposed in a xib or storyboard. – BJ Homer Aug 15 '14 at 20:11