比如要看看 一个textView由哪些部件组成, 可以用遍历下这个控件,打印查看log;
- 导入头文件
#import <objc/runtime.h>
#import <objc/message.h>
2.遍历(textView为例子)
unsigned int count = 0;
Ivar *ivars = class_copyIvarList([UITextView class], &count);
for (int i = 0; i < count; i++) {
Ivar ivar = ivars[i];
const char *name = ivar_getName(ivar);
NSString *objcName = [NSString stringWithUTF8String:name];
NSLog(@"%d : %@",i,objcName);
}
3.查看log
2017-07-03 13:38:49.255 WritersAssistant[70082:862920] 0 : _private
2017-07-03 13:38:49.255 WritersAssistant[70082:862920] 1 : _textStorage
2017-07-03 13:38:49.255 WritersAssistant[70082:862920] 2 : _textContainer
2017-07-03 13:38:49.256 WritersAssistant[70082:862920] 3 : _layoutManager
2017-07-03 13:38:49.256 WritersAssistant[70082:862920] 4 : _containerView
2017-07-03 13:38:49.256 WritersAssistant[70082:862920] 5 : _inputDelegate
2017-07-03 13:38:49.256 WritersAssistant[70082:862920] 6 : _tokenizer
2017-07-03 13:38:49.256 WritersAssistant[70082:862920] 7 : _inputController
2017-07-03 13:38:49.256 WritersAssistant[70082:862920] 8 : _interactionAssistant
2017-07-03 13:38:49.257 WritersAssistant[70082:862920] 9 : _textInputTraits
2017-07-03 13:38:49.257 WritersAssistant[70082:862920] 10 : _autoscroll
2017-07-03 13:38:49.257 WritersAssistant[70082:862920] 11 : _tvFlags
2017-07-03 13:38:49.257 WritersAssistant[70082:862920] 12 : _contentSizeUpdateSeqNo
2017-07-03 13:38:49.257 WritersAssistant[70082:862920] 13 : _scrollTarget
2017-07-03 13:38:49.257 WritersAssistant[70082:862920] 14 : _scrollPositionDontRecordCount
2017-07-03 13:38:49.258 WritersAssistant[70082:862920] 15 : _scrollPosition
2017-07-03 13:38:49.258 WritersAssistant[70082:862920] 16 : _offsetFromScrollPosition
2017-07-03 13:38:49.258 WritersAssistant[70082:862920] 17 : _linkInteractionItem
2017-07-03 13:38:49.258 WritersAssistant[70082:862920] 18 : _dataDetectorTypes
2017-07-03 13:38:49.258 WritersAssistant[70082:862920] 19 : _preferredMaxLayoutWidth
2017-07-03 13:38:49.258 WritersAssistant[70082:862920] 20 : _placeholderLabel
2017-07-03 13:38:49.259 WritersAssistant[70082:862920] 21 : _inputAccessoryView
2017-07-03 13:38:49.259 WritersAssistant[70082:862920] 22 : _linkTextAttributes
2017-07-03 13:38:49.259 WritersAssistant[70082:862920] 23 : _streamingManager
2017-07-03 13:38:49.260 WritersAssistant[70082:862920] 24 : _characterStreamingManager
2017-07-03 13:38:49.260 WritersAssistant[70082:862920] 25 : _siriAnimationStyle
2017-07-03 13:38:49.260 WritersAssistant[70082:862920] 26 : _siriParameters
2017-07-03 13:38:49.260 WritersAssistant[70082:862920] 27 : _firstBaselineOffsetFromTop
2017-07-03 13:38:49.260 WritersAssistant[70082:862920] 28 : _lastBaselineOffsetFromBottom
2017-07-03 13:38:49.260 WritersAssistant[70082:862920] 29 : _cuiCatalog
2017-07-03 13:38:49.261 WritersAssistant[70082:862920] 30 : _beforeFreezingTextContainerInset
2017-07-03 13:38:49.261 WritersAssistant[70082:862920] 31 : _duringFreezingTextContainerInset
2017-07-03 13:38:49.261 WritersAssistant[70082:862920] 32 : _beforeFreezingFrameSize
2017-07-03 13:38:49.262 WritersAssistant[70082:862920] 33 : _unfreezingTextContainerSize
2017-07-03 13:38:49.262 WritersAssistant[70082:862920] 34 : _adjustsFontForContentSizeCategory
2017-07-03 13:38:49.262 WritersAssistant[70082:862920] 35 : _clearsOnInsertion
2017-07-03 13:38:49.262 WritersAssistant[70082:862920] 36 : _multilineContextWidth
2017-07-03 13:38:49.263 WritersAssistant[70082:862920] 37 : _inputView