ios - swift -IOS : UIalertController position

标签 ios swift uialertview uialertcontroller

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

相关文章:

iphone - insertRowsAtIndexPaths 为每一行调用 cellForRowAtIndexPath

iphone - 为 iPhone 的 UIButton 添加特定的触摸事件

ios - 如何在触摸 UIAlertView 之外的任何地方时关闭它?

c++ - Header实现变量重定义不显示错误

ios - UIViewController 不响应旋转功能

ios - 如何在 Swift 中列出所有符合协议(protocol)的类?

arrays - 如何将 Swift 字符串集转换为数组

ios - 将 UILabel 添加到图像

ios - UIAlertView 导致更改导航栏按钮的 titleLabel

ios - 是否可以声明类似 lambda 函数的东西,UIAlert 中的 OK 按钮将执行什么操作?