ios - 边框有背景颜色渗透

标签 ios iphone swift xcode swift3

<分区>

我将背景颜色设置为白色边框,边框从背景中渗出。我希望蓝线消失。你能建议这个问题的解决方案吗?

下面是我的代码。下面是我正在谈论的图像。

[ Border example Image

self.imageView.layer.borderColor = UIColor.white.cgColor
self.imageView.layer.borderWidth = 3
self.imageView.backgroundColor = UIColor.blue
self.imageView.layer.cornerRadius = CGFloat(CircleDiameter/2)

最佳答案

我想这就是 iOS 渲染对具有正 cornerRadius 的图层所做的,我测试过添加一个白色圆 View 与具有相同大小的蓝色圆 View 重叠,出现相同的情况:

enter image description here

其实通过borderWidth Document层的边界是从接收者的边界绘制的,所以它和我上面提到的情况是一样的:

When this value is greater than 0.0, the layer draws a border using the current borderColor value. The border is drawn inset from the receiver’s bounds by the value specified in this property. It is composited above the receiver’s contents and sublayers and includes the effects of the cornerRadius property.

因此边框 + 圆度 = iOS 上的悲伤,我认为您需要另一种方式来实现您的设计。

关于ios - 边框有背景颜色渗透,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44080363/

相关文章:

ios - 表达式类型 'NSMutableArray!' 在没有更多上下文的情况下不明确

ios - 如何在允许用户交互的同时为按钮设置动画? (Xcode 8, iOS 10)

ios - 更改 QLPreviewController 中的导航栏颜色

iphone - 检测到对 iPhone 麦克风的吹气吗?

iphone - UISearchBar 右对齐放大镜图标

swift - 获取当前时间作为字符串 swift 3.0

ios - 从外部类向 UIButton 添加目标

ios - 从 JSON 填充表

ios - NSDate 时间从 12 小时格式转换为 24 小时格式

ios - 变量 NSString anos 使用 NSLocalizedString Xcode