但是,我注意到在本地化过程中,UIButton的实际大小在运行时会发生变化,但是按钮的边界/帧与脚本中的值保持不变。例如,在英语中,按钮的宽度为70。因为60字是比较短的。这导致UIBezierPath被过度使用(UI最初是用英语设计的)到70,当用户使用中文本地化时(我们没有语言切换,它只是基于IOS系统语言)。
UIButton在故事板中没有预设的宽度/高度,它是灰色的,因此它取决于文本。
扩展名.swift:
extension UIView {
func cornerRadius(usingCorners corners: UIRectCorner, cornerRadius: CGSize) {
let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: cornerRadius)
...not important, no bounds/frame manupulation
}
}
视图控制器.swift:
override func viewDidLoad() {
super.viewDidLoad()
takePhotoButton.cornerRadius(usingCorners: [.topRight, .bottomRight], cornerRadius: CGSize(size: 5))
}