我想知道如何更改UIAlertAction标题的字体。我假设,这可以通过为特定键设置一个值来完成。例如,要设置图像,您可以执行以下操作:
action.setValue(image, forKey: "image")是否有所有可用密钥的列表?我不知道该用哪个键来更改字体、左对齐/右对齐标题等。
发布于 2019-01-21 13:56:35
class_copyIvarList可能正是您所需要的。
斯威夫特
extension UIAlertAction {
static var propertyNames: [String] {
var outCount: UInt32 = 0
guard let ivars = class_copyIvarList(self, &outCount) else {
return []
}
var result = [String]()
let count = Int(outCount)
for i in 0..<count {
let pro: Ivar = ivars[i]
guard let ivarName = ivar_getName(pro) else {
continue
}
guard let name = String(utf8String: ivarName) else {
continue
}
result.append(name)
}
return result
}
}然后
print(UIAlertAction.propertyNames)输出结果是
["_title", "_titleTextAlignment", "_enabled", "_checked", "_isPreferred", "_imageTintColor", "_titleTextColor", "_style", "_handler", "_simpleHandler", "_image", "_shouldDismissHandler", "__descriptiveText", "_contentViewController", "_keyCommandInput", "_keyCommandModifierFlags", "__representer", "__interfaceActionRepresentation", "__alertController"]发布于 2015-11-19 18:07:01
您可以使用它来更改UIAlertAction标题的颜色。
UIAlertController *alertController = [UIAlertController
alertControllerWithTitle:@"alert view"
message:@"hello alert controller"
preferredStyle:UIAlertControllerStyleAlert];
alertController.view.tintColor = [UIColor greenColor];
UIAlertAction *cancelAction = [UIAlertAction
actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction *action)
{
}];
[alertController addAction:cancelAction];
[self.navigationController presentViewController: alertController animated:YES completion:nil];或
https://stackoverflow.com/questions/30056236
复制相似问题