如何摆脱在 iOS 7.1.1 中使用 layer.cornerRadius 圆角的 UIView 中的细边框?
问题描述:
我有一个自定义的 UIView,它通过像这样使用 layer.cornerRadius 来圆角:
I have a customized UIView that rounds its corners by using layer.cornerRadius like this:
- (void)layoutSubviews
{
[super layoutSubviews];
self.layer.cornerRadius = self.frame.size.width / 2.0;
self.layer.borderColor = [UIColor whiteColor].CGColor;
self.layer.borderWidth = 2.0;
self.layer.masksToBounds = YES;
self.backgroundColor = [UIColor redColor];
}
我怎样才能去掉外面很薄的红色圆圈?
How can I get rid of the very thin outer red circle?
答
好吧,一个更有效的方法是将这个函数复制粘贴到自定义视图的 .m 文件中,并在 drawRect 中调用它方法:
Well, a more efficient way to do what you need would be to copy paste this function in the .m file of your custom view and call it in the drawRect method:
- (void)drawRoundedViewWithFrame: (CGRect)frame color:(UIColor *)color
{
//// roundCircle Drawing
UIBezierPath* roundCirclePath = [UIBezierPath bezierPathWithOvalInRect: frame];
[color setFill];
[roundCirclePath fill];
[UIColor.whiteColor setStroke];
roundCirclePath.lineWidth = 2;
[roundCirclePath stroke];
}