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
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.
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.
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)
Using the same layer object:
view.layer.borderWidth = 1; view.layer.borderColor = [[UIColor whiteColor] CGColor];
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With