objc_runtime

获取某个类的成员变量;

    unsigned int numIvars; //成员变量个数
    Ivar *vars = class_copyIvarList([UISearchBar class], &numIvars);
    NSString *key=nil;
    for(int i = 0; i < numIvars; i++) {
        Ivar thisIvar = vars[i];
        key = [NSString stringWithUTF8String:ivar_getName(thisIvar)];  //获取成员变量的名字
        NSLog(@"variable name :%@", key);
        key = [NSString stringWithUTF8String:ivar_getTypeEncoding(thisIvar)]; //获取成员变量的数据类型
        NSLog(@"variable type :%@", key);
    }
    free(vars);

获取成员函数

 Method *meth = class_copyMethodList(NSClassFromString(@"UIView"), &numIvars);
    for(int i = 0; i < numIvars; i++) {
        Method thisIvar = meth[i];
        SEL sel = method_getName(thisIvar);
        const char *name = sel_getName(sel);
        NSLog(@"zp method :%s", name);
    }
    free(meth);

UISearchBar的私有变量

_searchField
_promptLabel
_cancelButton
_delegate
_controller
_barTintColor
_separator
_cancelButtonText
_scopes
_selectedScope
_background
_scopeBar
_scopeBarContainerView
_contentInsetPrivate
_indexWidth
_effectiveContentInset
_shadowView
_appearanceStorage
_searchDisplayControllerNavigationItem
_scopeBarBackgroundView
_animatedAppearanceBarButtonItem
_backdrop
_backdropStyle
_maskView
_tapToActivateGestureRecognizer
_cancelBarButtonItem
_textInputTraits
_leftButton
_dataSource
_titleLocation
_overlayRects
_searchBarFlags
__forceCenteredPlaceholderLayout
__transplanting
_statusBarTintColor
_inputAccessoryView
_barPosition
_searchBarStyle
__searchController
__scopeBarPosition

你可能感兴趣的:(objc_runtime)