Sunday, July 15, 2012

How to add Shadow,Border and Round corner to View programatically

here is simplest way what I do, When I need to add Shadow, Border or Round Corners Effects on any view

in ViewController.h

1. add QuartzCore.framwork in your project

2. add the UIView in XIB via Interface Builder

3. create UIView's IBOutlet and Hook-up with it
@property (weak, nonatomic) IBOutlet UIView *backgoundWall;

in ViewController.m

4. import QurtzCore header file.
#import <QuartzCore/QuartzCore.h>

3. synthesise the View property variable
@synthesize backgoundWall;

4. in viewDidLoad method add Shadow 

- (void)viewDidLoad
    [super viewDidLoad];    

    backgoundWall.layer.shadowColor =[UIColor blackColor].CGColor;
    backgoundWall.layer.shadowRadius =3.0;
    backgoundWall.layer.shadowOpacity =0.8;
    backgoundWall.layer.cornerRadius =5.0;
    backgoundWall.layer.shadowOffset =CGSizeMake(0, 7);
    backgoundWall.layer.borderColor = [UIColor lightGrayColor].CGColor;
    backgoundWall.layer.borderWidth =2.0;

5. Here is the result screen

Cheers!! We did it.

I would love to here you feedback!!