gpt4 book ai didi

swift - 如何在 UIActionSheet 中添加多行文本

转载 作者:行者123 更新时间:2023-12-03 22:04:47 28 4
gpt4 key购买 nike

enter image description here

如何在 UIActionSheet swift 中添加带有自定义字体的多行文本。我试过\n。但这不起作用。这可能还是不可能。

这是我的代码。

    alert.addAction(UIAlertAction(title: "line 1.\n %C line 2,\n %C line", style: .default , handler:{ (UIAlertAction)in
print("User click Approve button")
}))

alert.addAction(UIAlertAction(title: "Edit", style: .default , handler:{ (UIAlertAction)in
print("User click Edit button")
}))

alert.addAction(UIAlertAction(title: "Delete", style: .destructive , handler:{ (UIAlertAction)in
print("User click Delete button")
}))

alert.addAction(UIAlertAction(title: "Dismiss", style: .cancel, handler:{ (UIAlertAction)in
print("User click Dismiss button")
}))

self.present(alert, animated: true, completion: {
print("completion block")
})

最佳答案

试试下面的代码。

let optionMenu = UIAlertController(title: "Choose Class", message: "", preferredStyle: .actionSheet)
let course1 = UIAlertAction(title: "Computer Science(1st year) \n Digital Electronics", style: .default)
let course2 = UIAlertAction(title: "Computer Science(2nd year) \n Digital Electronics", style: .default)
let cancel = UIAlertAction(title: "Cancel", style: .cancel)
optionMenu.addAction(course1)
optionMenu.addAction(course2)
optionMenu.addAction(cancel)
self.present(optionMenu, animated: true, completion: nil)

// Setting up the number of lines and doing a word wrapping
UILabel.appearance(whenContainedInInstancesOf:[UIAlertController.self]).numberOfLines = 2
UILabel.appearance(whenContainedInInstancesOf:[UIAlertController.self]).lineBreakMode = .byWordWrapping

输出

Output Image

关于swift - 如何在 UIActionSheet 中添加多行文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57806732/

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