Tutorial by Examples: autolayout

Auto layout is used to arrange views so that they look good on any device and orientation. Constraints are the rules that tell how everything should be laid down. They include pinning edges, centering, and setting sizes, among other things. Auto layout is enabled by default, but you can double chec...
For bezier path to get resized based on the view frame, override the drawRect of view that you are drawing the bezier path : - (void)drawRect:(CGRect)frame { UIBezierPath* rectanglePath = [UIBezierPath bezierPathWithRect: CGRectMake(CGRectGetMinX(frame), CGRectGetMinY(frame), CGRectGetWidth(f...
Without Auto Layout, animation is accomplished changing a view's frame over time. With Auto Layout, the constraints dictate the view frame, so you have to animate the constraints instead. This indirection makes animation harder to visualize. Here are the ways to animate with Auto Layout: Change ...
Simple steps to use scrollview with autolayout. Create a new project with single view application Select the default viewcontroller and change its screen size to iPhone-4inch from attributes inspector. Add a scrollview to your viewcontroller's view as follows and set background color to blue ...
This project is a self-contained example done completely in the Interface Builder. You should be able to work through it in 10 minutes or less. Then you can apply the concepts you learned to your own project. Here I just use UIViews but they can represent whatever view you like (ie, button, label...
Sometimes you may want to perform some additional actions to Auto Layout calculations done by UIKit itself. Example: when you have a UIView that has a maskLayer, you may need to update maskLayer as soon as Auto Layout changes UIView's frame // CustomView.m - (void)layoutSubviews { [super la...
Making an app adaptive – that is, responding to size class changes by changing your layout – often involves lots of help from the Auto Layout system. One of the primary ways apps become adaptive is by updating the active Auto Layout constraints when a view's size class changes. For example, conside...
UIView *view = [[UIView alloc] init]; [self.view addSubview:view]; //Use the function if you want to use height as constraint [self addView:view onParentView:self.view withHeight:200.f]; //Use this function if you want to add view with respect to parent and should resize with it [self a...

Page 1 of 1