如何摆脱在 iOS 7.1.1 中使用 layer.cornerRadius 圆角的 UIView 中的细边框? [英] How to get rid of thin border in a UIView rounded with layer.cornerRadius in iOS 7.1.1?
本文介绍了如何摆脱在 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];
}
这篇关于如何摆脱在 iOS 7.1.1 中使用 layer.cornerRadius 圆角的 UIView 中的细边框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文