我想更改弹出框的宽度并保持高度不变
例如,如果您在iPad上打开弹出窗口,则高度约为屏幕的70%-80%。我想保持不变,但是需要增加宽度
我可以使用此块块,但在这里我也必须输入高度,这是我不想要的。
let vc = segue.destinationViewController
vc.preferredContentSize = CGSize(width: 200, height: 300)
非常感谢。
使height
调整为屏幕尺寸
var heightVariable = (self.view.frame.size.height * 70) / 100
现在,使用heightVariable
,高度将始终为屏幕高度的%70。因此,您不必将高度设置为常数
let vc = segue.destinationViewController
vc.preferredContentSize = CGSize(width: 200, height: heightVariable) // change width
顺便说一下,您可以使用UIDevice.current.userInterfaceIdiom
来检测设备并更改视图的属性,如:
if UIDevice.current.userInterfaceIdiom == .pad{
// change width
}else if UIDevice.current.userInterfaceIdiom == .phone{
// change width
}