Rounding UITextField angles in ViewDidLoad only affects left corners

I am trying to round the upper and lower border of two UITextField

Result ViewDidLoad()

ViewDidLoad Result

Result in ViewDidAppear

ViewDidAppear Result

The task ViewDidAppearforces the border to change after half a second of loading the view, which is not very good in my situation,

Does anyone know why it only rounds the left corner in a method ViewDidLoad?

any suggestions?

* Update *

viewDidLayoutSubviews coincides with ViewDidLoad

Here is the code I use to round corners

extension UITextField {
    func roundCorners(corners:UIRectCorner, radius: CGFloat) {
        let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
        let mask = CAShapeLayer()
        mask.path = path.CGPath
        self.layer.masksToBounds = true
        self.layer.mask = mask
    }
}

AND

self.FirstTextField.roundCorners(UIRectCorner.TopRight | UIRectCorner.TopLeft, radius: 10.0)
self.SecondTextField.roundCorners(UIRectCorner.BottomLeft | UIRectCorner.BottomRight, radius: 10.0)
+4
source share
3 answers

The only thing I ever expected to fix was to send to the main queue

dispatch_async(dispatch_get_main_queue(),{
      self.FirstTextField.roundCorners(UIRectCorner.TopRight | UIRectCorner.TopLeft, radius: 10.0)
      self.SecondTextField.roundCorners(UIRectCorner.BottomLeft | UIRectCorner.BottomRight, radius: 10.0)
});

Now I do not know if this can be ineffective or not, but yes, it works: D

- , , :)

+5

- (void)viewDidLayoutSubviews

+1

You need the layer mask to match its borders

self.layer.masksToBounds = true

EDIT:

Try using and instead of |, I believe that from the moment you use it, it takes only the first corner or.

self.FirstTextField.roundCorners(UIRectCorner.TopRight & UIRectCorner.TopLeft, radius: 10.0)
self.SecondTextField.roundCorners(UIRectCorner.BottomLeft & UIRectCorner.BottomRight, radius: 10.0)
0
source

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


All Articles