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

I had a code snippet as shown below that was used very well until I switched to Swift 3 to draw a border around the UIView. I just want this to be possible 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)
+4
source share
1 answer

I had similar problems doing calculations with frame sizes in viewDidLoad and awakeFromNib. Everything worked dandy in fast 2.3, and then everything quickly disappeared.

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 () in advance

I chose the latter.

+2

Source: https://habr.com/ru/post/1648296/


All Articles