我正在尝试创建自定义 alertView,但我遇到了 Alert 大小的问题 所以我的问题是: 我怎么知道左角的X位置和右角的X位置?
最佳答案
你可以得到类似的 x 位置,
x = self.view.frame.size.width/2.0 - yourCustomAlertView.frame.size.width/ 2.0
y也一样,
y = self.view.frame.size.height/2.0 - yourCustomAlertView.frame.size.height/ 2.0
更新:(如评论中所述)
您可以添加 width constraint
就像添加 height constraint
这样您的代码看起来像,
var height:NSLayoutConstraint = NSLayoutConstraint(item: alertController.view, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: 200);
var width : NSLayoutConstraint = NSLayoutConstraint(item: alertController.view, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: 300);
alertController.view.addConstraint(height);
alertController.view.addConstraint(width);
关于ios - swift -IOS : UIalertController position,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39894961/