gpt4 book ai didi

ios - UIAlertAction 按钮文本左对齐

转载 作者:可可西里 更新时间:2023-10-31 23:56:45 26 4
gpt4 key购买 nike

我想将 UIAlertAction 文本对齐方式向左对齐,并添加如图所示的图标。我花了很多时间在谷歌上寻找解决方案,但没有找到正确的答案。警报标题的每个正文帖子都不是警报操作标题。 enter image description here

请给我建议swift 的正确方法。

谢谢!!

最佳答案

您可以使用下面的示例代码来做到这一点。简单易行。

swift 4

let actionSheetAlertController: UIAlertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)

let cancelActionButton = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
actionSheetAlertController.addAction(cancelActionButton)


let documentsActionButton = UIAlertAction(title: "Documents", style: .default, handler: nil)
actionSheetAlertController.addAction(documentsActionButton)
documentsActionButton.setValue(#imageLiteral(resourceName: "doccument"), forKey: "image")
documentsActionButton.setValue(kCAAlignmentLeft, forKey: "titleTextAlignment")

let cameraActionButton = UIAlertAction(title: "Camera", style: .default, handler: nil)
actionSheetAlertController.addAction(cameraActionButton)
cameraActionButton.setValue(#imageLiteral(resourceName: "camera"), forKey: "image")
cameraActionButton.setValue(kCAAlignmentLeft, forKey: "titleTextAlignment")

let galleryActionButton = UIAlertAction(title: "Gallery", style: .default, handler: nil)
actionSheetAlertController.addAction(galleryActionButton)
galleryActionButton.setValue(#imageLiteral(resourceName: "gallery"), forKey: "image")
galleryActionButton.setValue(kCAAlignmentLeft, forKey: "titleTextAlignment")

actionSheetAlertController.view.tintColor = kTHEME_COLOR
self.present(actionSheetAlertController, animated: true, completion: nil)

关于ios - UIAlertAction 按钮文本左对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47370823/

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