由于UIProgressHUD
需要访问私人API, 所以我希望构建一个圆角和白色边框UIView
。 我知道要出角球轮是:UIView与圆角和白色边框
view.layer.cornerRadius = 5;
但如何使UIView的具有同时圆角和白色边框?
欢迎任何评论
感谢 InterDev中
由于UIProgressHUD
需要访问私人API, 所以我希望构建一个圆角和白色边框UIView
。 我知道要出角球轮是:UIView与圆角和白色边框
view.layer.cornerRadius = 5;
但如何使UIView的具有同时圆角和白色边框?
欢迎任何评论
感谢 InterDev中
从同一层对象:
view.layer.borderWidth = 1;
view.layer.borderColor = [[UIColor whiteColor] CGColor];
有视图层边框属性,以及:如:
view.layer.borderWidth = 1;
view.layer.borderColor = [UIColor redColor].CGColor;
[view.layer setBorderWidth:2];
[view.layer setBorderColor:[[UIColor whiteColor]CGColor]];
代码来获得圆角和边框
#import <QuartzCore/QuartzCore.h>
view.layer.cornerRadius = 10;
view.layer.borderWidth = 1;
view.layer.borderColor = [[UIColor whiteColor] CGColor];
有时用白色边框圆角半径不能正常工作所以我用UIBezierPath
和CAShapeLayer
。
为了使圆角半径
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;
为了使边框白色
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];
它将工作。希望这有助于
view.layer.cornerRadius = 5;
view.clipsToBounds = YES;
view.layer.borderWidth = 1;
view.layer.borderColor = [UIColor whiteColor].CGColor;
CALayer的是核心动画,不UIKit中的一部分。因此,它需要一个CGColor,而不是UIColor。 – MarkPowell 2010-12-01 17:35:05
哦,是的,抱歉,我只是从我的头上打字。 – 2010-12-01 19:52:05