[英]Preserve round edges of UIButton
尝试在用户旋转设备时保留 UIButton 的“圆度”:
func resizeButtons() {
startButton.layer.masksToBounds = true
startButton.layer.cornerRadius = self.startButton.frame.size.width / 2
startButton.layer.borderColor = UIColor.blackColor().CGColor
startButton.layer.borderWidth = 1.0
}
override func didRotateFromInterfaceOrientation(fromInterfaceOrientation: UIInterfaceOrientation) {
switch UIDevice.currentDevice().orientation{
case .Portrait:
self.resizeButtons()
case .PortraitUpsideDown:
self.resizeButtons()
case .LandscapeLeft:
self.resizeButtons()
case .LandscapeRight:
self.resizeButtons()
default:
print("default")
}
}
我正在使用自动布局和 StoryBoards(按钮纵横比 1:1,纵横比按钮到容器视图 1:3,按钮中心水平和垂直到容器)。
结果有点麻烦和“丑陋”,因为设备旋转 UIButton 变成圆角矩形,然后变成完整的圆形。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.