gpt4 book ai didi

iOS - 如何在 UIAlertController swift 中的新行中添加操作

转载 作者:行者123 更新时间:2023-11-30 11:11:59 26 4
gpt4 key购买 nike

我需要在新行中添加操作,例如:alertActionsWithNewLines

我正在尝试这段代码:

let uncheckInAlert = UIAlertController(title: "Are you sure you want to uncheck-in?", message: "", preferredStyle: .alert)
uncheckInAlert.setTitleImage(UIImage(named: "fail_Icon"))
uncheckInAlert.addAction(UIAlertAction(title: "Yes", style: .default, handler: { (action) -> Void in
self.userUncheckIn()
}))
uncheckInAlert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
self.present(uncheckInAlert, animated: true, completion: nil)

但结果我有类似的东西:alertActionsInOneLine 。如果操作标题很大,则操作会自动转入新行。通过小 Action 标题, Action 被分组在一行中。有什么办法可以做到这一点吗?

最佳答案

您无法设置任何标志来更改 Apple 警报按钮的布局方式。然而,具有 alert 样式的 UIAlertController 会在无法在水平布局中正确容纳按钮文本的整个字符串时自动将其按钮布局更改为垂直。因此,如果按钮的文本足够长,它就会改变布局。

虽然这是您问题的解决方案,但我不建议在按钮的文本中添加任意空格或不必要的长字符串,以便 Apple 在生产应用程序中垂直布局按钮。它滥用了标准组件,一旦字符串本地化为其他语言,它就很容易开始崩溃。为了自然地实现所需的行为,我建议创建您自己的自定义 View 来垂直显示按钮。

关于iOS - 如何在 UIAlertController swift 中的新行中添加操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52099047/

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