我们在开发的过程中用到的一些控件,明明一些属性我们一定会用到,但是是查看API就是没有,这个时候一般人会吐槽一下苹果;随后就是选择自己封装或者使用其他的实现方式来实现 。但是好多时候从网上搜出来的时候,人家大多都是通过KVC实现,这时候我就想人家咋获得的这些属性,我们怎么就不知道呢!其实很简单的……
1、首先引入头文件:#import <objc/runtime.h>
unsigned int count = 0;
Ivar *ivars = class_copyIvarList([UITextField class], &count);
for (int i = 0; i<count; i++) {
Ivar ivar = ivars[i];
NSLog(@"UITextField--->%s------%s", ivar_getName(ivar),ivar_getTypeEncoding(ivar));
}
UITextField--->_textStorage------@"_UICascadingTextStorage"
UITextField--->_borderStyle------q
UITextField--->_minimumFontSize------d
UITextField--->_delegate------@
UITextField--->_background------@"UIImage"
UITextField--->_disabledBackground------@"UIImage"
UITextField--->_clearButtonMode------q
UITextField--->_leftView------@"UIView"
UITextField--->_leftViewMode------q
UITextField--->_rightView------@"UIView"
UITextField--->_rightViewMode------q
UITextField--->_traits------@"UITextInputTraits"
UITextField--->_nonAtomTraits------@"UITextInputTraits"
UITextField--->_fullFontSize------d
UITextField--->_padding------{UIEdgeInsets="top"d"left"d"bottom"d"right"d}
UITextField--->_selectionRangeWhenNotEditing------{_NSRange="location"Q"length"Q}
UITextField--->_scrollXOffset------i
UITextField--->_scrollYOffset------i
UITextField--->_progress------f
UITextField--->_clearButton------@"UIButton"
UITextField--->_clearButtonOffset------{CGSize="width"d"height"d}
UITextField--->_leftViewOffset------{CGSize="width"d"height"d}
UITextField--->_rightViewOffset------{CGSize="width"d"height"d}
UITextField--->_backgroundView------@"UITextFieldBorderView"
UITextField--->_disabledBackgroundView------@"UITextFieldBorderView"
UITextField--->_systemBackgroundView------@"UITextFieldBackgroundView"
UITextField--->_floatingContentView------@"_UIFloatingContentView"
UITextField--->_contentBackdropView------@"UIVisualEffectView"
UITextField--->_fieldEditorBackgroundView------@"_UIDetachedFieldEditorBackgroundView"
UITextField--->_fieldEditorEffectView------@"UIVisualEffectView"
UITextField--->_displayLabel------@"UITextFieldLabel"
UITextField--->_placeholderLabel------@"UITextFieldLabel"
UITextField--->_suffixLabel------@"UITextFieldLabel"
UITextField--->_prefixLabel------@"UITextFieldLabel"
UITextField--->_iconView------@"UIImageView"
UITextField--->_label------@"UILabel"
UITextField--->_labelOffset------d
UITextField--->_interactionAssistant------@"UITextInteractionAssistant"
UITextField--->_selectGestureRecognizer------@"UITapGestureRecognizer"
UITextField--->_inputView------@"UIView"
UITextField--->_inputAccessoryView------@"UIView"
UITextField--->_systemInputViewController------@"UISystemInputViewController"
UITextField--->_atomBackgroundView------@"UITextFieldAtomBackgroundView"
UITextField--->_textFieldFlags------{?="verticallyCenterText"b1"isAnimating"b4"inactiveHasDimAppearance"b1"becomesFirstResponderOnClearButtonTap"b1"clearsPlaceholderOnBeginEditing"b1"adjustsFontSizeToFitWidth"b1"fieldEditorAttached"b1"canBecomeFirstResponder"b1"shouldSuppressShouldBeginEditing"b1"inResignFirstResponder"b1"undoDisabled"b1"explicitAlignment"b1"implementsCustomDrawing"b1"needsClearing"b1"suppressContentChangedNotification"b1"allowsEditingTextAttributes"b1"usesAttributedText"b1"backgroundViewState"b2"clearingBehavior"b2"overridePasscodeStyle"b1"shouldResignWithoutUpdate"b1"blurEnabled"b1"disableFocus"b1}
UITextField--->_deferringBecomeFirstResponder------B
UITextField--->_avoidBecomeFirstResponder------B
UITextField--->_setSelectionRangeAfterFieldEditorIsAttached------B
UITextField--->_animateNextHighlightChange------B
UITextField--->_baselineLayoutConstraint------@"NSLayoutConstraint"
UITextField--->_baselineLayoutLabel------@"_UIBaselineLayoutStrut"