samir
samir

Reputation: 4551

Rounder corners in UIView

i have a UIView and i would like to round it and add shadow color like this image : image rounded

Upvotes: 1

Views: 129

Answers (2)

yoeriboven
yoeriboven

Reputation: 3571

To get the very same shadow as your image I would recommend you using a background image. Otherwise you should include <Quartzcore/Quartzcore.h> and use the following code:

view.layer.cornerRadius = 10;
view.frame = CGRectMake(15, 15, 100, 100);
view.backgroundColor = [UIColor redColor];
view.layer.shadowColor = [UIColor blackColor].CGColor;
view.layer.shadowOffset = CGSizeMake(2.0, 2.0);
view.layer.shadowOpacity = 0.8;
view.layer.shadowRadius = 10;

Some more information for the background image-option

Create a UIView that has the same width and height as the image including the shadow and assign the image to it this way:

view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"backgroundview.png"]];

Upvotes: 0

P.J
P.J

Reputation: 6587

For Rounder Corner

 CAShapeLayer * maskLayer = [CAShapeLayer layer];
    maskLayer.path = [UIBezierPath bezierPathWithRoundedRect: self.bounds byRoundingCorners: UIRectCornerBottomLeft | UIRectCornerTopRight cornerRadii: (CGSize){10.0, 10.}].CGPath;

    self.layer.mask = maskLayer;

For Shadow

self.layer.masksToBounds = NO;
self.layer.shadowOffset = CGSizeMake(-15, 20);
self.layer.shadowRadius = 5;
self.layer.shadowOpacity = 0.5;

Hope this helps you!

Upvotes: 2

Related Questions