首页 > 解决方案 > 获取 UIAlertAction 的大小

问题描述

有没有办法从 a 获取高度/宽度UIAlertAction

它似乎不是 的子类UIView,所以在 中是否为它设置了一个常量UIAlertController

标签: ioscocoa-touchuialertcontrolleruialertaction

解决方案


是的,您可以通过以下方式获取 UIAlertController 的高度/宽度

present(alertController, animated: true, completion: nil)
DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
    alertController.view.frame.height
}

注意:需要在当前 UIAlertController 之后放置一些延迟 你只会得到警报部分框架


推荐阅读