Set border around the view

There is no border property in UIView…. classes but we can access CALayer class to set border. Since layer property is defined in the UIView class, all of UIView inherited class can use this property to set border. It needs to have #import <QuartzCore/QuartzCore.h> to access CALayer.

view.layer.borderWidth = 1;
view.layer.borderColor = [[UIColor grayColor] CGColor];

Applying animation while resizing or moving the view

Animation can be applied while its frame, bounds, center, transform, alpha… is being changed.  The key is set start and end values between beginAnimations and commitAnimations, so called animation block.


[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration: 1.0];

// set original position
[view setFrame:CGRectMake(0, 0, 100, 100)];

// move and grow
[view setFrame:CGRectMake(100, 100, 200, 200)];

[UIView commitAnimations];