gpt4 book ai didi

ios - swift -IOS : UIalertController position

转载 作者:行者123 更新时间:2023-11-28 08:26:16 24 4
gpt4 key购买 nike

我正在尝试创建自定义 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com