当前位置: 首页 > 面试题库 >

如何更改UIAlertController的高度?

楚瑞
2023-03-14
问题内容

我创建了一个UIAlertController

let alertC = UIAlertController(title: "Title", message: "Message", preferredStyle: UIAlertControllerStyle.Alert)
alertC.addTextFieldWithConfigurationHandler(addTextField)
alertC.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Default, handler: nil))
alertC.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: okButton))
presentViewController(alertC, animated: true, completion: nil)

但是之后,我想更改UIAlertController的高度吗?我怎样才能做到这一点?


问题答案:

我发现您可以在显示视图控制器之前添加约束

 let alertController = UIAlertController(title: nil, message: "hello", preferredStyle: .alert)


    let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) { (action) in
        // hide action sheet
    }
    alertController.addAction(cancelAction)


    var height:NSLayoutConstraint = NSLayoutConstraint(item: alertController.view, attribute: NSLayoutConstraint.Attribute.height, relatedBy: NSLayoutConstraint.Relation.equal, toItem: nil, attribute: NSLayoutConstraint.Attribute.notAnAttribute, multiplier: 1, constant: self.view.frame.height * 0.80)
    alertController.view.addConstraint(height);
    self.present(alertController, animated: true, completion: nil)


 类似资料:
  • 问题内容: 我在中添加了。我想更改文本字段的高度。我已经尝试过这种方式: 没用 问题答案: 这具有 约束条件 。

  • 问题内容: 我可以改变颜色吗?标准颜色是蓝色。而且它与标准iOS应用程序非常接近。是否可定制?我该如何改变颜色?例如按钮颜色。 谢谢! 问题答案: 您可以只更改基础视图的,但是由于iOS 9(https://openradar.appspot.com/22209332)中引入的一个已知错误,因此tintColor被应用程序窗口的覆盖。 您可以: 在AppDelegate中更改应用程序。 } 在完成

  • 问题内容: 如何使用Swift更改UIAlertController的Title字体? 我不是在谈论消息的颜色,我不是在谈论按钮的颜色。 我说的是标题。 问题答案: 在我的答案中添加了正确的代码行,因为它比下面的答案更加简洁。

  • 问题内容: 我想知道在Android中更改ProgressBar高度的最简单方法是什么? 谢谢, 托梅克 问题答案: 如果进度条是在XML布局中定义的,则看起来就像您这样定义其高度: 但是我只是从这篇文章中猜测一下。

  • 问题内容: 我正在使用ui-grid。我有很多行,所以才使用滚动。一切正常,直到我尝试更改行的高度。然后滚动变得一团糟。我在这里添加了一个示例http://plnkr.co/edit/S6ylwOVgcQp7CSsZZxpR?p=preview 这是ui-grid网站上的教程之一-我唯一更改的是CSS。我添加了这些规则。 如果删除了上述CSS规则,滚动就可以正常工作。因此,我要么需要添加更多CSS

  • 这是输出: 我试图制作一个应用程序,但当我使用时,我得到了两个按钮之间的空间 我需要一个接一个没有空间 如果使用小部件,不起作用 我尝试了,但我无法清除这些内容。 我尝试使这种类型的. 有人知道或知道这件事吗?