UIButtons are not correctly shaped on all devices

后端 未结 1 1341
北荒
北荒 2021-01-27 11:16

I\'ve an UIView Controller with four square buttons and I\'ve set them round with a border. It works perfectly on iPhone 8 and iPhone X but in iPhone SE and iPhone 8 Plus the UI

1条回答
  •  无人及你
    2021-01-27 11:27

    set button cornerRadius in viewDidLayoutSubviews method of viewcontroller

     override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()
        // Edit it to round
        topLeftButtonImage.layer.cornerRadius = topLeftButtonImage.bounds.size.height / 2
        topLeftButtonImage.clipsToBounds = true
    
        // Add border
        topLeftButtonImage.layer.borderColor = UIColor.white.cgColor // Button border color
        topLeftButtonImage.layer.borderWidth = 4 // Button border width
    }
    

    0 讨论(0)
提交回复
热议问题