ios - 如何在 iOS 7.1.1 中摆脱使用 Layer.cornerRadius 圆角的 UIView 中的细边框?

标签 ios uiview

我有一个自定义的 UIView,它通过使用 layer.cornerRadius 来圆角,如下所示:

- (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];
}

如何去掉外面非常细的红圈?

最佳答案

嗯,一种更有效的方法来完成您需要的操作,是将这个函数复制粘贴到自定义 View 的 .m 文件中,并在 drawRect 方法中调用它:

- (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 - 如何在 iOS 7.1.1 中摆脱使用 Layer.cornerRadius 圆角的 UIView 中的细边框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23891033/

相关文章:

iphone - 我可以使用 PAN over Bluetooth 将配件连接到 iPad 吗?

ios - 如何取消 CGContextClipToRect? (iOS)

ios - 在可重用的 UIView 中,我应该将 UIButtons 的选择器放在哪里?

ios - 无法更改 View 中绘制的圆的颜色

ios - [context assignObject : toPersistentStore ] do? 是什么

ios - 停止在iOS Web应用程序的屏幕边缘上滚动吗?

objective-c - 类型 "struct objc_method"的定义不完整

ios - 显示键盘时如何决定滚动哪个 UIScrollView

ios - 父 UIView 不包含/剪辑 subview

iphone - iPhone SDK 中的自动调整大小如何工作?