EmbCoder
EmbCoder

Reputation: 572

Swift 3 add a custom border to one of the edges of UIView

I had a code snippet as shown below that used to work just fine until I migrated to Swift 3, to be able to draw a border around the UIView. I just want to be able to do this at the bottom of the UIView.

    let border = CALayer()
    border.frame = CGRect(x: 0, y: self.basicDetailsView.frame.height - 2, width: self.basicDetailsView.frame.width, height: 2)
    border.backgroundColor = UIColor.gray().cgColor

    self.basicDetailsView.layer.addSublayer(border)

Upvotes: 4

Views: 3877

Answers (1)

Kate
Kate

Reputation: 246

I had similar problems performing calculations with frame sizes in viewDidLoad and awakeFromNib. Everything worked dandily in swift 2.3 and then things disappeared in swift 3

This post helped me: cornerRadius stopped working in Swift 2.3 / iOS 10 / Xcode 8

You can move the code to viewDidAppear, or call self.view.layoutIfNeeded() beforehand

I opted for the latter.

Upvotes: 2

Related Questions