Dil*_*hra 5 xcode nsobject uialertview uiactionsheet swift
如何在 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")
})
Run Code Online (Sandbox Code Playgroud)
尝试下面的代码。
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
Run Code Online (Sandbox Code Playgroud)
输出
| 归档时间: |
|
| 查看次数: |
2534 次 |
| 最近记录: |