What is the Xcode 11 beta Colors library for in Interface Builder? - interface-builder

In the nib editor (Interface Builder) in Xcode 11 beta, when you edit a storyboard or xib file, when you summon the Library, it now has three sections: Objects, Images, and Colors. What's the Colors section for? I can see that it lists named colors from the asset catalog, but I can't seem to do anything with that list; if I drag a color onto the Canvas or a view or whatever, nothing happens.

Related

Set color of NSStatusItem OSX 10.10 Swift

I have seen that some icons in the Menu Bar have colours, but I can't find a way to color the NSStatusItem I'm working on. I use an image (inside Images.xcassets) with color, but it just tints in white or black. I'm using MacOS 10.10 and Swift. I have also searched Apple documentation with no luck.
Thanks for your time.
Those status items with color are actually doing it the wrong (old) way. You're supposed to use template images so that the system can apply effects and show it properly in Dark mode. For a template image, the color is ignored. Only the alpha channel matters.
If you really want to defy Apple's recommendation, simply use a non-template image. Don't suffix your image name with "Template" and don't set the template property in code.
From the AppKit release notes for 10.10:
NSStatusItem appearance and Dark Menu support (Section added since WWDC seed)
There are a number of stylistic changes added and supported by
NSStatusItem, including appearance changes for Dark Menus. Template
images should always be used to ensure correct styling based on the
various states the status item can be in (light menu, dark menu,
inactive light, inactive dark, selected, disabled, etc).
NSStatusBarButton’s appearsDisabled property can be used to give the
image a disabled or “off” look without having the item be functionally
disabled. …

Change object color in Xcode

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?
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.
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.

How do I make screenshot of Xcode storyboard?

I need to take a screenshot of whole storyboard as an image. Is that possible? I need it to give to my designer.
Ideally I'd like to get 1 big image, make some changes (number views, etc) and save it as JPG
Xcode doesn't have any features for printing or exporting an image of your storyboard. (Though that might make a good feature request to send to Apple.)
Your best bet is to resize your project window as large as possible (and hide the navigator and utility sidebars) and take a screenshot. You might be able to employ a trick or two in getting everything to fit:
If you're on a Mac with a Retina Display, change your screen resolution to one of the "more space" options so your Xcode window can be bigger. (For example, on a 5K iMac you can choose the "looks like 3200 x 1800" size, which renders a 6400 x 3600 screen and downscales it to fit the actual display hardware.)
Zoom out on the storyboard with the Editor > Canvas > Zoom menu commands. In Xcode 8, the zoomed-out storyboard uses the same rendering/editing engine as the regular-size view — which means that on a Retina display, your shrunken-down views will still be legible.
Resize the window larger than the screen, then take a window screenshot (Cmd-Shift-4, then spacebar, then click the window). You can do this with AppleScript:
tell application "Xcode" to set bounds of front window to {0, 0, 4000, 3000}
But that'll still limit its height to that of the screen (minus menubar and Dock). You can drag the window to the bottom of the screen and edge-resize it upward to get some extra height, though.
One more thing: Since the beginning of storyboards (way back in Xcode... 5, I think?), you've never needed to have "one storyboard to rule them all" in your project. In fact, there are lots of reasons why it might make sense to break your app into multiple storyboards. And of course, if you have multiple storyboards, you can screenshot them separately and integrate them however you like for a design presentation.
Using multiple storyboards used to mean you couldn't segue between view controllers in separate storyboards (you'd have to instantiate and present view controllers programmatically), but since Xcode 7 you can insert a "Storyboard Reference" in one storyboard to link to a view controller in a different storyboard. And if you have a big storyboard you want to break up, there's a tool for that. (Select some view controllers, choose Editor > Refactor to Storyboard...)

In Xcode 5, why don't UITextViews display their text in Interface Builder?

In older versions of Xcode (pre Xcode 5) my UITextViews display their text in the Storyboard. In Xcode 5 the UITextViews are blue, labeled "UITextView" in white and the text is not displayed until runtime. I assume their is a preference somewhere to force the issue but I can't seem to find it.
If you double tap your UITextFields in the interface builder you can edit the text, which will be displayed in your Storyboard. But if the text of your UITextField is set programatically the text will not be displayed in the Interface builder.

In Xcode Interface Builder how do I control how the element behave when the view is resized?

In older Xcode I have a little window where I could mark braces and band things to control how a NSView behaves when its parent is resized. In the new Xcode that is missing and the controls are doing whatever they feel like.
Is there any way to get this control back? (current version: Version 4.3.2 (4E2002))
Starting with Xcode 4.3 when you create a Cocoa application project, the xib file uses auto layout. Auto layout replaces the size inspector's autosizing mask.
If you want to use the autosizing mask, the solution is to turn off auto layout. Select the xib file from the project navigator, open the file inspector, and deselect the Use Auto Layout checkbox.
Read Constraints Express Relationships Between Views to learn how views are constrained in Xcode 4. In fact, you probably want the entire Cocoa Auto Layout Guide.
Briefly, when you add a view to your view hierarchy, it comes with some constraints. Select the view in the and you'll see some blue lines that look a bit like I-beams -- these represent the constraints. Click on one of them and you can edit its properties in the attributes inspector. But how you should set the attributes probably won't make much sense until you've read about how constraints work in the document linked above.

Resources