Creating a percentage based iOS layout

Using Xcode 6.0, you can now specify proportional width or height in Interface Builder. Steps for percentage height from superview: While both the child view and its superview are selected, add an “equal height” constraint (or “equal width” if you wish to have a proportional width). Then change the “multiplier” of the constraint you just … Read more

Does an IBOutlet needs to be a property & synthesized?

On Mac OS X, IBOutlets are connected like this: Look for a method called set<OutletName>:. If it exists call it. If no method exists, look for an instance variable named <OutletName>, set it without retaining. On iPhone OS, IBOutlets are connected like this: call [object setValue:outletValue forKey:@”<OutletName>”] The behavior of set value for key is … Read more

Apple Interface Builder: adding subview to UIImageView

You cannot add a subview to UIImageView in interface builder for reasons only known to Apple! You are right in saying that you can addSubview programmatically, but then, the overhead of setting autoresizing masks and placements of subviews should all be handled in code, which is cumbersome. So there is an easy workaround. Instead of … Read more

Swift – IBOutletCollection equivalent

Update: This works properly in Xcode now – “Outlet Collection” is one of the connection options in Interface Builder, which creates something that looks like: @IBOutlet var labelCollection: [UILabel]! While we’re waiting for a fix, you can approximate this using a computed property. Let’s say my view has five UILabels that I want in a … Read more

Do I have to call addSubview after calling addChildViewController?

1) Do I have to call addSubview after calling addChildViewController? Yes 2) Do I have to call removeFromSuperview before calling removeChildViewController? Not quite You should call removeFromParentViewController: instead of removeChildViewController: You should also call willMoveToParentViewController: For adding / removing, you can refer to this great category : UIViewController + Container – (void)containerAddChildViewController:(UIViewController *)childViewController { [self … Read more