ios - 带有圆角和白色边框的UIView有轮廓,如何去掉轮廓

标签 ios uiview

<分区>

我使用以下代码创建了一个具有红色背景颜色和 1pt 宽度白色边框的 UIView。

let myView = UIView(frame: CGRect(x: 100, y: 100, width: 20, height: 20))
self.view.addSubview(myView)
myView.backgroundColor = UIColor.red
myView.layer.borderColor = UIColor.white.cgColor
myView.layer.borderWidth = 1
myView.layer.cornerRadius = 10

但是myView渲染出来的是红色轮廓,怎么去掉呢?附上放大的截图。

Below is the enlarged screenshot

最佳答案

这不是你问题的答案

但是如果您创建另一个 View 并将其作为 subview 添加到您的主视图中,您可以做得更好:

let myView = UIView(frame: CGRect(x: 100, y: 100, width: 20, height: 20))

let redView = UIView(frame: CGRect(x: 0, y: 0, width: 20, height: 20))


redView.backgroundColor = UIColor.red
myView.layer.borderColor = UIColor.white.cgColor
myView.layer.borderWidth = 1
redView.layer.borderColor = UIColor.white.cgColor
redView.layer.borderWidth = 1

myView.addSubview(redView)
self.view.addSubview(myView)

myView.layer.cornerRadius = 10
myView.clipsToBounds = true

结果将是:

enter image description here

关于ios - 带有圆角和白色边框的UIView有轮廓,如何去掉轮廓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55100046/

相关文章:

ios - 在 View 已经可见时更改 uitabbar 图标

ios - 在 View Controller 中加载自定义 UI 元素的位置

objective-c - GLubyte/GLushort 使用问题

swift - 如何将 UIView 子类化并在其中添加另一个具有相同框架的 UIView

ios - 将联系人地址保存到统一联系人会导致(CNErrorDomain 错误 500)

iphone - 将大量 Sqlite 行加载到 UITableView 中

ios - 将 UIView 移动到另一个 UIView 中

iOS - 如何关闭键盘?

ios - 菜单栏和图像/按钮未正确对齐

ios - __IPHONE_OS_VERSION_MIN_REQUIRED 请解释