NSKeyValueCoding
协议的函数 func setValue(_ value: AnyObject?,forKey key: String)
来改变UIPickerDate的文本颜色,方法如下: class coloredDatePicker: UIDatePicker { var changed = false overrIDe func addSubvIEw(vIEw: UIVIEw) { if !changed { changed = true self.setValue(UIcolor(red: 0.42,green: 0.42,blue: 0.42,Alpha: 1),forKey: "textcolor") } super.addSubvIEw(vIEw) }}
关于question的答案.它完美无缺.
但我的答案是:
我如何知道该类提供的名称,如上面使用的textcolor?
我试图找到任何得到所有名称或在文档中,但到目前为止,我还没有找到任何东西来获得类似上述情况下提供的键.
解决方法 objective-c运行时为属性提供了这种类型的反射:ID UIDatePickerClass = objc_getClass("UIDatePicker");unsigned int outCount,i;objc_property_t *propertIEs = class_copyPropertyList(UIDatePickerClass,&outCount);for (i = 0; i < outCount; i++) { objc_property_t property = propertIEs[i]; fprintf(stdout,"%s %s\n",property_getname(property),property_getAttributes(property));}
参考文档:https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ObjCRuntimeRef/index.html#//apple_ref/c/func/class_copyPropertyList
编辑 – 斯威夫特也有基本的反思:https://stackoverflow.com/a/24069875/1385467
总结以上是内存溢出为你收集整理的ios – 获取课程的所有键全部内容,希望文章能够帮你解决ios – 获取课程的所有键所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)