需求
有的时候我们需要更改系统类的某个属性时,例如 UIAlertControler 的文字大小,颜色,排列方式的时候,系统类有没有给出相应的属性或者方法进行修改,这就需要我们用KVO进行修改了,但是这个时候,又不知道具体的Key是什么 ,所以就有了如下的方法
1. 我们利用runtime 获取对象的所有属性 --- 引入 objc/runtime.h
#include <objc/runtime.h>
2.以系统对象为例,正常情况下我们无法查看系统对象的私有属性,如下方法可以得到其全部属性。
这里 我们以UINavigationBar为例
unsigned int count;
// 获取键值列表
objc_property_t *propertyList = class_copyPropertyList([self.navigationController.navigationBar class], &count);
for (unsigned int i = 0; i<count; i++) {
const char *propertyName = property_getName(propertyList[i]);
NSLog(@"property----="">%@", [NSString stringWithUTF8String:propertyName]);
}
3 打印如下
2017-11-15 16:19:10.442611+0800 SchoolLife[4592:262991] property----=>hash
2017-11-15 16:19:10.442979+0800 SchoolLife[4592:262991] property----=>superclass
2017-11-15 16:19:10.443111+0800 SchoolLife[4592:262991] property----=>description
2017-11-15 16:19:10.443223+0800 SchoolLife[4592:262991] property----=>debugDescription
2017-11-15 16:19:10.443481+0800 SchoolLife[4592:262991] property----=>_backIndicatorLeftMargin
2017-11-15 16:19:10.444126+0800 SchoolLife[4592:262991] property----=>_barTranslucence
2017-11-15 16:19:10.444470+0800 SchoolLife[4592:262991] property----=>_overrideBackgroundExtension
2017-11-15 16:19:10.444937+0800 SchoolLife[4592:262991] property----=>_deferShadowToSearchBar
2017-11-15 16:19:10.445051+0800 SchoolLife[4592:262991] property----=>_animationIds
2017-11-15 16:19:10.445151+0800 SchoolLife[4592:262991] property----=>_startedAnimationTracking
2017-11-15 16:19:10.445265+0800 SchoolLife[4592:262991] property----=>_stack
2017-11-15 16:19:10.445343+0800 SchoolLife[4592:262991] property----=>_isContainedInPopover
2017-11-15 16:19:10.445415+0800 SchoolLife[4592:262991] property----=>_heightIncludingBackground
2017-11-15 16:19:10.445494+0800 SchoolLife[4592:262991] property----=>refreshControlHost
2017-11-15 16:19:10.445604+0800 SchoolLife[4592:262991] property----=>_wantsLargeTitleDisplayed
2017-11-15 16:19:10.445712+0800 SchoolLife[4592:262991] property----=>backgroundEffects
2017-11-15 16:19:10.445782+0800 SchoolLife[4592:262991] property----=>requestedContentSize
2017-11-15 16:19:10.445885+0800 SchoolLife[4592:262991] property----=>currentContentSize
2017-11-15 16:19:10.446106+0800 SchoolLife[4592:262991] property----=>_userContentGuide
2017-11-15 16:19:10.446302+0800 SchoolLife[4592:262991] property----=>state
2017-11-15 16:19:10.446472+0800 SchoolLife[4592:262991] property----=>locked
2017-11-15 16:19:10.446673+0800 SchoolLife[4592:262991] property----=>currentBackButton
2017-11-15 16:19:10.446846+0800 SchoolLife[4592:262991] property----=>currentLeftView
2017-11-15 16:19:10.447086+0800 SchoolLife[4592:262991] property----=>currentRightView
2017-11-15 16:19:10.447238+0800 SchoolLife[4592:262991] property----=>isMinibar
2017-11-15 16:19:10.447417+0800 SchoolLife[4592:262991] property----=>forceFullHeightInLandscape
2017-11-15 16:19:10.447661+0800 SchoolLife[4592:262991] property----=>_useInlineBackgroundHeightWhenLarge
2017-11-15 16:19:10.447865+0800 SchoolLife[4592:262991] property----=>_backgroundOpacity
2017-11-15 16:19:10.448059+0800 SchoolLife[4592:262991] property----=>_titleOpacity
2017-11-15 16:19:10.448247+0800 SchoolLife[4592:262991] property----=>alwaysUseDefaultMetrics
2017-11-15 16:19:10.448404+0800 SchoolLife[4592:262991] property----=>_hidesShadow
2017-11-15 16:19:10.448553+0800 SchoolLife[4592:262991] property----=>_wantsLetterpressContent
2017-11-15 16:19:10.448752+0800 SchoolLife[4592:262991] property----=>_backgroundView
2017-11-15 16:19:10.448946+0800 SchoolLife[4592:262991] property----=>_shadowAlpha
2017-11-15 16:19:10.449186+0800 SchoolLife[4592:262991] property----=>_disableBlurTinting
2017-11-15 16:19:10.449345+0800 SchoolLife[4592:262991] property----=>_backdropViewLayerGroupName
2017-11-15 16:19:10.449540+0800 SchoolLife[4592:262991] property----=>_requestedMaxBackButtonWidth
2017-11-15 16:19:10.449710+0800 SchoolLife[4592:262991] property----=>_accessibilityButtonBackgroundTintColor
2017-11-15 16:19:10.449902+0800 SchoolLife[4592:262991] property----=>barStyle
2017-11-15 16:19:10.450050+0800 SchoolLife[4592:262991] property----=>delegate
2017-11-15 16:19:10.450248+0800 SchoolLife[4592:262991] property----=>translucent
2017-11-15 16:19:10.450406+0800 SchoolLife[4592:262991] property----=>topItem
2017-11-15 16:19:10.450623+0800 SchoolLife[4592:262991] property----=>backItem
2017-11-15 16:19:10.450808+0800 SchoolLife[4592:262991] property----=>items
2017-11-15 16:19:10.451023+0800 SchoolLife[4592:262991] property----=>prefersLargeTitles
2017-11-15 16:19:10.451233+0800 SchoolLife[4592:262991] property----=>tintColor
2017-11-15 16:19:10.451460+0800 SchoolLife[4592:262991] property----=>barTintColor
2017-11-15 16:19:10.451633+0800 SchoolLife[4592:262991] property----=>shadowImage
2017-11-15 16:19:10.451816+0800 SchoolLife[4592:262991] property----=>titleTextAttributes
2017-11-15 16:19:10.452005+0800 SchoolLife[4592:262991] property----=>largeTitleTextAttributes
2017-11-15 16:19:10.452224+0800 SchoolLife[4592:262991] property----=>backIndicatorImage
2017-11-15 16:19:10.452398+0800 SchoolLife[4592:262991] property----=>backIndicatorTransitionMaskImage
2017-11-15 16:19:10.452574+0800 SchoolLife[4592:262991] property----=>hash
2017-11-15 16:19:10.452730+0800 SchoolLife[4592:262991] property----=>superclass
2017-11-15 16:19:10.453018+0800 SchoolLife[4592:262991] property----=>description
2017-11-15 16:19:10.453181+0800 SchoolLife[4592:262991] property----=>debugDescription
2017-11-15 16:19:10.453387+0800 SchoolLife[4592:262991] property----=>barPosition