iphone - top - user defined runtime attributes border color

UIView with round corner and white border (4)

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

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

There are border properties in the layer of the view as well: eg:

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

code to get rounded corners and border

#import <QuartzCore/QuartzCore.h>
view.layer.cornerRadius = 10;
view.layer.borderWidth = 1;
view.layer.borderColor = [[UIColor whiteColor] CGColor];

[view.layer setBorderWidth:2];

[view.layer setBorderColor:[[UIColor whiteColor]CGColor]];