首页 > 解决方案 > iOS 13 将圆形按钮更改为对角线

问题描述

我在视图控制器中有以下两个按钮,它们在 iOS 12 和 XCode 11 中显示我需要的圆形按钮,但是当我使用 iOS 13 和 XCode 11 时,它们是对角线的,如图所示。

self.saveBtn.frame.size = CGSize(width:70,height:70)
self.saveBtn.layer.cornerRadius = self.saveBtn.frame.size.height/2.0
self.saveBtn.layer.borderColor = UIColor.lightGray.cgColor
self.saveBtn.layer.borderWidth = 1.5
self.saveBtn.clipsToBounds = true
self.saveBtn.titleLabel?.font = UIFont(name:"HelveticaNeue", size:18)
self.saveBtn.titleLabel?.adjustsFontSizeToFitWidth = true

self.cancelBtn.frame.size = CGSize(width:70,height:70)
self.cancelBtn.layer.cornerRadius = self.cancelBtn.frame.size.height/2.0
self.cancelBtn.layer.borderColor = UIColor.lightGray.cgColor
self.cancelBtn.layer.borderWidth = 1.5
self.cancelBtn.clipsToBounds = true
self.cancelBtn.titleLabel?.font = UIFont(name:"HelveticaNeue", size:18)
self.cancelBtn.titleLabel?.adjustsFontSizeToFitWidth = true

Xcode 11 和 iOS12

XCode 11 和 iOS 13

如何将这些按钮转换回圆形?

标签: iosswiftuibutton

解决方案


我不确定,但试试这个

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
    }

   override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        self.saveBtn.frame.size = CGSize(width:70,height:70)
        self.saveBtn.layer.cornerRadius = self.saveBtn.frame.size.height/2.0
        self.saveBtn.layer.borderColor = UIColor.lightGray.cgColor
        self.saveBtn.layer.borderWidth = 1.5
        self.saveBtn.clipsToBounds = true
        self.saveBtn.titleLabel?.font = UIFont(name:"HelveticaNeue", size:18)
        self.saveBtn.titleLabel?.adjustsFontSizeToFitWidth = true

        self.cancelBtn.frame.size = CGSize(width:70,height:70)
        self.cancelBtn.layer.cornerRadius = self.cancelBtn.frame.size.height/2.0
        self.cancelBtn.layer.borderColor = UIColor.lightGray.cgColor
        self.cancelBtn.layer.borderWidth = 1.5
        self.cancelBtn.clipsToBounds = true
        self.cancelBtn.titleLabel?.font = UIFont(name:"HelveticaNeue", size:18)
        self.cancelBtn.titleLabel?.adjustsFontSizeToFitWidth = true
   }
}

推荐阅读