Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIView with round corner and white border

Tags:

iphone

Due to UIProgressHUD need to access private api, so I hope to construct an UIView with round corner and white border. I know to make the corner round is:

view.layer.cornerRadius = 5; 

But how to make the uiview has round corner and white border at the same time?

Welcome any comment

Thanks interdev

like image 862
arachide Avatar asked Dec 01 '10 14:12

arachide


People also ask

How do you round UIView corners?

If you start with a regular UIView it has square corners. You can give it round corners by changing the cornerRadius property of the view's layer . and smaller values give less rounded corners. Both clipsToBounds and masksToBounds are equivalent.

How do I add inner shadow to UIView with rounded corners?

Add subview with the same color which will be centered on the parent and will be with several pixels smaller. Like this you will have space from each side of the parent. On the parent turn on clipping subviews and add shadow to the inner view. Like this, you can have an inner shadow.

How do you add corner radius to a storyboard?

Select the view that you want to round and open its Identity Inspector. In the User Defined Runtime Attributes section, add the following two entries: Key Path: layer. cornerRadius , Type: Number, Value: (whatever radius you want)


2 Answers

Using the same layer object:

view.layer.borderWidth = 1; view.layer.borderColor = [[UIColor whiteColor] CGColor]; 
like image 124
MarkPowell Avatar answered Sep 22 '22 18:09

MarkPowell


Sometimes corner radius with white border does not work properly so I use UIBezierPath and CAShapeLayer.

For make the corner radius

UIBezierPath *maskPath; maskPath = [UIBezierPath bezierPathWithRoundedRect:self.imageView.bounds byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight | UIRectCornerBottomLeft | UIRectCornerBottomRight) cornerRadii:CGSizeMake(10.0, 10.0)];  CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init]; maskLayer.frame = self.view.bounds; maskLayer.path = maskPath.CGPath; self.imageView.layer.mask = maskLayer; 

For make the border white

CAShapeLayer*   borderShape = [CAShapeLayer layer]; borderShape.frame = self.imageView.bounds; borderShape.path = maskPath.CGPath; borderShape.strokeColor = [UIColor whiteColor].CGColor; borderShape.fillColor = nil; borderShape.lineWidth = 3; [self.imageView.layer addSublayer:borderShape]; 

It will work. Hope this help

like image 24
Linh Avatar answered Sep 24 '22 18:09

Linh