UIAlertAction值列表 [英] UIAlertAction list of values

查看:254
本文介绍了UIAlertAction值列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找出如何更改UIAlertAction标题的字体类型. 我假设可以通过为特定键设置一个值来完成. 例如,要设置图像,您可以执行以下操作:

I'm trying to figure out how to change font type for UIAlertAction title. I'm assuming, it can be done by setting a value for particular key. For instance, to set an image you would do this:

action.setValue(image, forKey: "image")

是否有所有可用键的列表?我不知道要使用哪个键来更改字体,将标题左/右对齐等等.

Is there a list of all keys that are available? I can't figure out which key to use for changing font, aligning the title left/right, etc...

推荐答案

class_copyIvarList可能就是您所需要的.

class_copyIvarList may be what you need.

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"]

这篇关于UIAlertAction值列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆