0
votes

I have an UIButton and an UIView where i want to remove bottom border for the button and top border for the view. The image below show an UIButton. When I press this UIButton the UIView will be added as subview (like a dropdown menu), But I want the button and the view merge with each other so it will look like on "box".

I know how to set border width and color:

self.layer.borderWidth = 1
self.layer.borderColor = UIColor(CGColor: "#616366".CGColor).CGColor

But I don't know if it is possible to remove on border line. Hope you guys can help - Thank you

enter image description here

1

1 Answers

0
votes

The easiest way is going to be to change your layout a little bit so that rather than adding the UIView as a subview of the UIButton you add them both as siblings to a container view, and draw the border on the container view.

Kind of like this:

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