@IBDesignable crashing agent

Xcode’s Interface Builder requires that you implement both or neither initializers for @IBDesignable classes to render properly in IB. If you implement required init(coder aDecoder: NSCoder) you’ll need to override init(frame: CGRect) as well, otherwise “the agent will crash” as seen in the errors thrown by Xcode. To do so add the following code to … Read more

Color in storyboard not matching UIColor

Xcode 8+, iOS 10+ I recently faced this problem and none of the posted answers did it. It turns out that with the release of iOS 10 SDK, the UIColor initializer init(red:green:blue:alpha:) now uses the extended sRGB range, so you have to set accordingly when configuring your color values on the Storyboard. See Apple’s documentation: … Read more

Xcode 11 add new constraints set zero: use set value instead of default / standard

Seems like a bug (don’t forget to file with Apple). Here’s a simple workaround: When you fill in the number in the “popover”, instead of typing 0, type 0.01. This will prevent the number from changing mysteriously to “Standard”. Okay, so 0.01 is not the same as 0 but it’s close enough that you can’t … Read more

Programmatically send to front/back elements created from interface builder

There are a number of methods of UIView that allow you to modify the view hierarchy. bringSubviewToFront: sendSubviewToBack: insertSubview:atIndex: insertSubview:aboveSubview: insertSubview:belowSubview: exchangeSubviewAtIndex:withSubviewAtIndex: Since your views are already inserted into your superview, you could easily call bringSubviewToFront: once for each view in whatever order you like.

Alignment UIImageView with Aspect Fit

[EDIT – this code is a bit moldy being from 2011 and all but I incorporated @ArtOfWarefare’s mods] You can’t do this w/ UIImageView. I created a simple UIView subclass MyImageView that contains a UIImageView. Code below. // MyImageView.h #import <UIKit/UIKit.h> @interface MyImageView : UIView { UIImageView *_imageView; } @property (nonatomic, assign) UIImage *image; @end … Read more

How to send objects in NIB files to front/back?

Just to give a clean, up-to-date answer to this: Select an interface object, then “Editor | Arrange | Send to back/front/etc”, OR Select the window object, then click on ‘Window’ above the interface editor and select the objects it contains This pic shows where to click: Or you can expand the object browser, use the … Read more