我有一个 UIButton 和一个 UIView,我想删除按钮的底部边框和 View 的顶部边框。下图显示了一个 UIButton。当我按下这个 UIButton 时,UIView 将被添加为 subview (如下拉菜单),但我希望按钮和 View 彼此合并,这样它看起来就像在“盒子”上。
我知道如何设置边框宽度和颜色:
self.layer.borderWidth = 1
self.layer.borderColor = UIColor(CGColor: "#616366".CGColor).CGColor
但我不知道是否可以在边界线上删除。希望大家能帮忙 - 谢谢
最佳答案
最简单的方法是稍微改变你的布局,这样你就可以将它们作为同级添加,而不是将 UIView
添加为 UIButton
的 subview 到容器 View ,并在容器 View 上绘制边框。
有点像这样:
let button = UIButton(frame: CGRect(x: 0, y: 0, width: 100, height: 44))
button.setTitle("Button", forState: .Normal)
button.titleLabel?.textColor = UIColor.blackColor()
let container = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 44))
container.addSubview(button)
container.frame = button.frame
container.backgroundColor = UIColor.whiteColor()
container.layer.borderWidth = 5
container.layer.borderColor = UIColor.blackColor().CGColor
let added = UIView(frame:CGRect(x: 0, y: 44, width: 100, height: 200))
added.backgroundColor = UIColor.blueColor()
container.addSubview(added)
container.frame.size.height += added.frame.size.height
XCPlaygroundPage.currentPage.liveView = container
关于ios - 如何删除 UIButton 和 UIView 上的特定边框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33922101/