How to set default values for IBInspectable in Objective-C?

Since IBInspectable values are set after initWithCoder: and before awakeFromNib:, you can set the defaults in initWithCoder: method. @interface MyView : UIView @property (copy, nonatomic) IBInspectable NSString *myProp; @property (assign, nonatomic) BOOL createdFromIB; @end @implementation MyView – (id)initWithCoder:(NSCoder *)aDecoder { self = [super initWithCoder:aDecoder]; if(self != nil) { self.myProp = @”foo”; self.createdFromIB = YES; } … Read more

Is there a way for Interface Builder to render IBDesignable views which don’t override drawRect:

Thanks, @zisoft for the clueing me in on prepareForInterfaceBuilder. There a few nuances with Interface Builder’s render cycle which were the source of my issues and are worth noting… Confirmed: You don’t need to use -drawRect. Setting images on UIButton control states works. Arbitrary layer stacks seem to work if a few things are kept … Read more

Change character spacing on UILabel within Interface Builder

I know it’s not an Interface Builder solution, but you can create a UILabel extension and then add spacing to any UILabel you want: extension UILabel { func addCharacterSpacing(kernValue: Double = 1.15) { guard let text = text, !text.isEmpty else { return } let string = NSMutableAttributedString(string: text) string.addAttribute(NSAttributedString.Key.kern, value: kernValue, range: NSRange(location: 0, length: … Read more

Can I use setFrame and autolayout on the same view?

Yes, this can be done. If you set a view’s translatesAutoresizingMaskIntoConstraints = YES, then calls to setFrame: are automatically translated at runtime into layout constraints based on the view’s current autoresizingMask. This lets you mix frame-based layout with constraint-based layout. For instance you could use Auto Layout to define the layout of all of the … Read more

UIView backgroundColor disappears when UITableViewCell is selected

The problem here is that the [super] implementation of – (void) setSelected:(BOOL) selected animated:(BOOL) animated; sets all the background colors in the UITableViewCell to rgba(0,0,0,0). Why? Perhaps to make us all sweat? It is not that entire views disappear (as evidenced by the fact that if you change the views layer border properties, those are … Read more

Interface Builder degrades storyboards, resizes and repositions views in small increments

The most interesting clue in this mystery is that it seems especially bad when you open the same storyboard on a Retina display as opposed to a non-retina display. At first I was going back and forth between a 4k iMac and a pre-retina Macbook pro and was getting a large volume of changes (~300 … Read more

What are the benefits of using Storyboards instead of xib files in iOS programming?

A Storyboard is: A container for all your Scenes (View Controllers, Nav Controllers, TabBar Controllers, etc) A manager of connections and transitions between these scenes (these are called Segues) A nice way to manage how different controllers talk to each other Storyboards give you a complete look at the flow of your application that you … Read more