转自:http://blog.csdn.net/cubepeng/article/details/11284173

OS不允许使用ios私有api,使用私有api可以获得意想不到的效果 ,同时使用私有api是一个程序员的技术体现之一。至于怎么通过apple的审核,其实是有些办法的,但是不属于今天讨论的范围。私有api可以通过 dump头文件获得,也可以去github clone一份现成的,但是还是推荐自己去dump。但是我们今天不是讨论,如何使用dump到的api,而是通过一个例子来讨论如何通过查看头文件使用 私有api。

我们以UITextfield为例,其实这是个比较简单的控件,有一个蓝色输入的光标,可以在你输入的时候隐藏或者显示,但是并没有给我们提供改变光标颜 色的接口,这个时候我们如果要改变光标的颜色,必然要使用私有api(或者通过比较啰嗦的办法来做这这件事情)。
     我们首先需要dump一包头文件,如何class-dump,不是我们今天讨论的要点,现在我们贴上UITextfield的头文件。如果你觉得很长,直接拖到最后面。

[html] view plaincopy
  1. /*
  2. *     Generated by class-dump 3.4 (64 bit).
  3. *
  4. *     class-dump is Copyright (C) 1997-1998, 2000-2001, 2004-2012 by Steve Nygard.
  5. */
  6. #import <UIKit/UIControl.h>
  7. #import "NSCoding.h"
  8. #import "UIPopoverControllerDelegate.h"
  9. #import "UITextInput.h"
  10. @class NSArray, NSAttributedString, NSDictionary, NSString, UIButton, UIColor, UIFont, UIImage, UIImageView, UILabel, UITextFieldAtomBackgroundView, UITextFieldBackgroundView, UITextFieldBorderView, UITextFieldLabel, UITextInputTraits, UITextInteractionAssistant, UITextPosition, UITextRange, UIView, _UIBaselineLayoutStrut, _UITextServiceSession;
  11. @interface UITextField : UIControl <UIPopoverControllerDelegate, UITextInput, NSCoding>
  12. {
  13. NSAttributedString *_text;
  14. UIColor *_textColor;
  15. int _borderStyle;
  16. float _minimumFontSize;
  17. id _delegate;
  18. UIImage *_background;
  19. UIImage *_disabledBackground;
  20. int _clearButtonMode;
  21. UIView *_leftView;
  22. int _leftViewMode;
  23. UIView *_rightView;
  24. int _rightViewMode;
  25. UITextInputTraits *_traits;
  26. UITextInputTraits *_nonAtomTraits;
  27. float _fullFontSize;
  28. float _paddingLeft;
  29. float _paddingTop;
  30. float _paddingRight;
  31. float _paddingBottom;
  32. NSString *_textFont;
  33. struct _NSRange _selectionRange;
  34. int _scrollXOffset;
  35. int _scrollYOffset;
  36. float _progress;
  37. NSString *_style;
  38. UIButton *_clearButton;
  39. struct CGSize _clearButtonOffset;
  40. struct CGSize _leftViewOffset;
  41. struct CGSize _rightViewOffset;
  42. UITextFieldBorderView *_backgroundView;
  43. UITextFieldBorderView *_disabledBackgroundView;
  44. UITextFieldBackgroundView *_systemBackgroundView;
  45. UITextFieldLabel *_textLabel;
  46. UITextFieldLabel *_placeholderLabel;
  47. UITextFieldLabel *_suffixLabel;
  48. UITextFieldLabel *_prefixLabel;
  49. UIImageView *_iconView;
  50. UILabel *_label;
  51. float _labelOffset;
  52. UITextInteractionAssistant *_interactionAssistant;
  53. UIView *_inputView;
  54. UIView *_inputAccessoryView;
  55. UITextFieldAtomBackgroundView *_atomBackgroundView;
  56. UIColor *_shadowColor;
  57. struct CGSize _shadowOffset;
  58. float _shadowBlur;
  59. struct {
  60. unsigned int secureTextChanged:1;
  61. unsigned int guard:1;
  62. unsigned int delegateRespondsToHandleKeyDown:1;
  63. unsigned int verticallyCenterText:1;
  64. unsigned int isAnimating:4;
  65. unsigned int inactiveHasDimAppearance:1;
  66. unsigned int becomesFirstResponderOnClearButtonTap:1;
  67. unsigned int clearsOnBeginEditing:1;
  68. unsigned int clearsPlaceholderOnBeginEditing:1;
  69. unsigned int adjustsFontSizeToFitWidth:1;
  70. unsigned int fieldEditorAttached:1;
  71. unsigned int canBecomeFirstResponder:1;
  72. unsigned int shouldSuppressShouldBeginEditing:1;
  73. unsigned int inResignFirstResponder:1;
  74. unsigned int undoDisabled:1;
  75. unsigned int contentsRTL:1;
  76. unsigned int explicitAlignment:1;
  77. unsigned int implementsCustomDrawing:1;
  78. unsigned int needsClearing:1;
  79. unsigned int suppressContentChangedNotification:1;
  80. unsigned int allowsEditingTextAttributes:1;
  81. unsigned int usesAttributedText:1;
  82. unsigned int backgroundViewState:2;
  83. unsigned int clearsOnInsertion:1;
  84. } _textFieldFlags;
  85. _UITextServiceSession *_definitionSession;
  86. _UITextServiceSession *_learnSession;
  87. BOOL _deferringBecomeFirstResponder;
  88. BOOL _avoidBecomeFirstResponder;
  89. BOOL _setSelectionRangeAfterFieldEditorIsAttached;
  90. NSArray *_baselineLayoutConstraints;
  91. _UIBaselineLayoutStrut *_baselineLayoutLabel;
  92. }
  93. @property(retain) UIView *inputView; // @synthesize inputView=_inputView;
  94. @property(nonatomic) int rightViewMode; // @synthesize rightViewMode=_rightViewMode;
  95. @property(retain, nonatomic) UIView *rightView; // @synthesize rightView=_rightView;
  96. @property(nonatomic) int leftViewMode; // @synthesize leftViewMode=_leftViewMode;
  97. @property(retain, nonatomic) UIView *leftView; // @synthesize leftView=_leftView;
  98. @property(nonatomic) int clearButtonMode; // @synthesize clearButtonMode=_clearButtonMode;
  99. @property(retain, nonatomic) UIImage *disabledBackground; // @synthesize disabledBackground=_disabledBackground;
  100. @property(retain, nonatomic) UIImage *background; // @synthesize background=_background;
  101. @property(nonatomic) id <UITextFieldDelegate> delegate; // @synthesize delegate=_delegate;
  102. @property(nonatomic) float minimumFontSize; // @synthesize minimumFontSize=_minimumFontSize;
  103. @property(nonatomic) int borderStyle; // @synthesize borderStyle=_borderStyle;
  104. @property(retain, nonatomic, setter=_setBaselineLayoutLabel:) _UIBaselineLayoutStrut *_baselineLayoutLabel; // @synthesize _baselineLayoutLabel;
  105. @property(copy, nonatomic, setter=_setBaselineLayoutConstraints:) NSArray *_baselineLayoutConstraints; // @synthesize _baselineLayoutConstraints;
  106. - (void)setSelectionGranularity:(int)arg1;
  107. - (int)selectionGranularity;
  108. - (id)_findWebViewWordBoundaryFromPosition:(id)arg1;
  109. @property(nonatomic) int selectionAffinity;
  110. - (id)characterRangeAtPoint:(struct CGPoint)arg1;
  111. - (id)closestPositionToPoint:(struct CGPoint)arg1 withinRange:(id)arg2;
  112. - (id)closestPositionToPoint:(struct CGPoint)arg1;
  113. - (struct CGRect)caretRectForPosition:(id)arg1;
  114. - (struct CGRect)firstRectForRange:(id)arg1;
  115. - (void)setBaseWritingDirection:(int)arg1 forRange:(id)arg2;
  116. - (int)baseWritingDirectionForPosition:(id)arg1 inDirection:(int)arg2;
  117. - (id)characterRangeByExtendingPosition:(id)arg1 inDirection:(int)arg2;
  118. - (id)positionWithinRange:(id)arg1 farthestInDirection:(int)arg2;
  119. @property(readonly, nonatomic) id <UITextInputTokenizer> tokenizer;
  120. @property(nonatomic) id <UITextInputDelegate> inputDelegate;
  121. - (int)offsetFromPosition:(id)arg1 toPosition:(id)arg2;
  122. - (int)comparePosition:(id)arg1 toPosition:(id)arg2;
  123. - (id)positionFromPosition:(id)arg1 inDirection:(int)arg2 offset:(int)arg3;
  124. - (id)positionFromPosition:(id)arg1 offset:(int)arg2;
  125. - (id)textRangeFromPosition:(id)arg1 toPosition:(id)arg2;
  126. @property(readonly, nonatomic) UITextPosition *endOfDocument;
  127. @property(readonly, nonatomic) UITextPosition *beginningOfDocument;
  128. - (void)unmarkText;
  129. - (void)setMarkedText:(id)arg1 selectedRange:(struct _NSRange)arg2;
  130. @property(copy, nonatomic) NSDictionary *markedTextStyle;
  131. @property(readonly, nonatomic) UITextRange *markedTextRange;
  132. @property(copy) UITextRange *selectedTextRange;
  133. - (void)replaceRange:(id)arg1 withText:(id)arg2;
  134. - (id)textInRange:(id)arg1;
  135. - (BOOL)hasText;
  136. - (id)metadataDictionariesForDictationResults;
  137. - (struct CGRect)frameForDictationResultPlaceholder:(id)arg1;
  138. - (void)removeDictationResultPlaceholder:(id)arg1 willInsertResult:(BOOL)arg2;
  139. - (id)insertDictationResultPlaceholder;
  140. - (void)insertDictationResult:(id)arg1 withCorrectionIdentifier:(id)arg2;
  141. - (void)insertText:(id)arg1;
  142. - (void)deleteBackward;
  143. - (id)_proxyTextInput;
  144. - (BOOL)canPerformAction:(SEL)arg1 withSender:(id)arg2;
  145. - (BOOL)inPopover;
  146. - (void)_promptForReplace:(id)arg1;
  147. - (void)replace:(id)arg1;
  148. - (void)_showTextStyleOptions:(id)arg1;
  149. - (void)toggleUnderline:(id)arg1;
  150. - (void)toggleItalics:(id)arg1;
  151. - (void)toggleBoldface:(id)arg1;
  152. - (void)makeTextWritingDirectionLeftToRight:(id)arg1;
  153. - (void)makeTextWritingDirectionRightToLeft:(id)arg1;
  154. - (void)selectAll:(id)arg1;
  155. - (void)select:(id)arg1;
  156. - (void)paste:(id)arg1;
  157. - (void)_addShortcut:(id)arg1;
  158. - (void)_selectionMayChange:(id)arg1;
  159. - (BOOL)_isDisplayingReferenceLibraryViewController;
  160. - (void)_define:(id)arg1;
  161. - (void)copy:(id)arg1;
  162. - (void)cut:(id)arg1;
  163. - (id)webView;
  164. - (struct CGPoint)constrainedPoint:(struct CGPoint)arg1;
  165. - (unsigned int)offsetInMarkedTextForSelection:(id)arg1;
  166. - (struct CGRect)closestCaretRectInMarkedTextRangeForPoint:(struct CGPoint)arg1;
  167. - (id)selectedAttributedText;
  168. - (id)selectedText;
  169. - (id)selectionRectsForRange:(id)arg1;
  170. - (struct CGRect)_selectionClipRect;
  171. - (id)interactionAssistant;
  172. - (id)selectionView;
  173. - (void)cancelAutoscroll;
  174. - (void)startAutoscroll:(struct CGPoint)arg1;
  175. - (BOOL)hasSelection;
  176. - (id)_fieldEditor;
  177. - (void)endSelectionChange;
  178. - (void)beginSelectionChange;
  179. - (BOOL)isEditable;
  180. - (id)undoManager;
  181. - (int)atomStyle;
  182. - (void)setAtomStyle:(int)arg1;
  183. - (BOOL)drawsAsAtom;
  184. - (void)setDrawsAsAtom:(BOOL)arg1;
  185. - (void)setClearButtonOffset:(struct CGSize)arg1;
  186. - (void)_clearButtonClicked:(id)arg1;
  187. - (BOOL)isUndoEnabled;
  188. - (void)setUndoEnabled:(BOOL)arg1;
  189. - (void)setTextCentersVertically:(BOOL)arg1;
  190. - (void)setTextCentersHorizontally:(BOOL)arg1;
  191. - (void)setLabel:(id)arg1;
  192. - (id)textLabel;
  193. - (void)setLabelOffset:(float)arg1;
  194. - (BOOL)hasMarkedText;
  195. - (void)setProgress:(float)arg1;
  196. - (struct CGRect)iconRect;
  197. - (void)setBecomesFirstResponderOnClearButtonTap:(BOOL)arg1;
  198. - (struct CGSize)clearButtonOffset;
  199. - (void)setIcon:(id)arg1;
  200. - (unsigned int)characterOffsetAtPoint:(struct CGPoint)arg1;
  201. - (void)setSelectionRange:(struct _NSRange)arg1;
  202. - (struct _NSRange)selectionRange;
  203. - (void)clearText;
  204. - (void)layoutTilesNow;
  205. - (void)_resetSelectionUI;
  206. - (void)_clearSelectionUI;
  207. - (void)selectAll;
  208. - (void)setEnabled:(BOOL)arg1;
  209. - (void)_setEnabled:(BOOL)arg1 animated:(BOOL)arg2;
  210. - (void)setInactiveHasDimAppearance:(BOOL)arg1;
  211. - (void)setTextFont:(id)arg1;
  212. - (float)paddingRight;
  213. - (void)setPaddingRight:(float)arg1;
  214. - (float)paddingBottom;
  215. - (void)setPaddingBottom:(float)arg1;
  216. - (float)paddingTop;
  217. - (void)setPaddingTop:(float)arg1;
  218. - (float)paddingLeft;
  219. - (void)setPaddingLeft:(float)arg1;
  220. - (void)setPaddingTop:(float)arg1 paddingLeft:(float)arg2;
  221. - (void)drawBorder:(struct CGRect)arg1;
  222. - (void)drawRect:(struct CGRect)arg1;
  223. - (BOOL)_canDrawContent;
  224. - (BOOL)_implementsCustomDrawing;
  225. - (struct CGRect)editRect;
  226. - (struct CGRect)textRect;
  227. - (struct CGRect)clearButtonRect;
  228. - (void)setClearButtonStyle:(int)arg1;
  229. - (void)setTextAutorresizesToFit:(BOOL)arg1;
  230. - (void)setAutoresizesTextToFit:(BOOL)arg1;
  231. - (id)documentFragmentForPasteboardItemAtIndex:(int)arg1;
  232. - (id)_dictationInterpretations;
  233. - (id)supportedPasteboardTypesForCurrentSelection;
  234. - (BOOL)fieldEditor:(id)arg1 shouldReplaceWithText:(id)arg2;
  235. - (BOOL)fieldEditor:(id)arg1 shouldInsertText:(id)arg2 replacingRange:(struct _NSRange)arg3;
  236. - (void)fieldEditorDidChangeSelection:(id)arg1;
  237. - (struct _NSRange)fieldEditor:(id)arg1 willChangeSelectionFromCharacterRange:(struct _NSRange)arg2 toCharacterRange:(struct _NSRange)arg3;
  238. - (void)selectAllFromFieldEditor:(id)arg1;
  239. - (void)fieldEditorDidChange:(id)arg1;
  240. - (id)customOverlayContainer;
  241. - (void)keyboardInputChangedSelection:(id)arg1;
  242. - (BOOL)keyboardInputChanged:(id)arg1;
  243. - (BOOL)keyboardInputShouldDelete:(id)arg1;
  244. - (BOOL)keyboardInput:(id)arg1 shouldReplaceTextInRange:(struct _NSRange)arg2 replacementText:(id)arg3;
  245. - (BOOL)keyboardInput:(id)arg1 shouldInsertText:(id)arg2 isMarkedText:(BOOL)arg3;
  246. - (void)_applicationResuming:(id)arg1;
  247. - (void)willDetachFieldEditor:(id)arg1;
  248. - (void)attachFieldEditor:(id)arg1;
  249. - (void)willAttachFieldEditor:(id)arg1;
  250. - (void)_drawTextInRect:(struct CGRect)arg1 forLabel:(id)arg2;
  251. - (void)drawPrefixInRect:(struct CGRect)arg1;
  252. - (void)drawSuffixInRect:(struct CGRect)arg1;
  253. - (void)drawPlaceholderInRect:(struct CGRect)arg1;
  254. - (void)drawTextInRect:(struct CGRect)arg1;
  255. - (struct CGRect)rightViewRectForBounds:(struct CGRect)arg1;
  256. - (struct CGRect)leftViewRectForBounds:(struct CGRect)arg1;
  257. - (struct CGRect)_baselineLeftViewRectForBounds:(struct CGRect)arg1;
  258. - (struct CGRect)clearButtonRectForBounds:(struct CGRect)arg1;
  259. - (struct CGRect)editingRectForBounds:(struct CGRect)arg1;
  260. - (struct CGRect)placeholderRectForBounds:(struct CGRect)arg1;
  261. - (struct CGRect)textRectForBounds:(struct CGRect)arg1;
  262. - (struct CGRect)borderRectForBounds:(struct CGRect)arg1;
  263. @property(retain) UIView *inputAccessoryView;
  264. @property(readonly, nonatomic, getter=isEditing) BOOL editing;
  265. - (id)backgroundColor;
  266. - (void)setBackgroundColor:(id)arg1;
  267. @property(copy, nonatomic) NSDictionary *typingAttributes;
  268. @property(nonatomic) BOOL allowsEditingTextAttributes;
  269. @property(nonatomic) BOOL adjustsFontSizeToFitWidth;
  270. - (void)setClearsPlaceholderOnBeginEditing:(BOOL)arg1;
  271. - (BOOL)clearsPlaceholderOnBeginEditing;
  272. @property(nonatomic) BOOL clearsOnBeginEditing;
  273. - (void)_setPrefix:(id)arg1;
  274. - (void)_setSuffix:(id)arg1 withColor:(id)arg2;
  275. @property(copy, nonatomic) NSAttributedString *attributedPlaceholder;
  276. @property(copy, nonatomic) NSString *placeholder;
  277. - (void)createPlaceholderIfNecessary;
  278. - (void)finishedSettingPlaceholder;
  279. - (id)createTextLabelWithTextColor:(id)arg1;
  280. - (void)_createBaselineLayoutLabelIfNecessary;
  281. - (id)createPlaceholderLabelWithFont:(id)arg1 andTextAlignment:(int)arg2;
  282. - (void)setContentVerticalAlignment:(int)arg1;
  283. @property(nonatomic) int textAlignment;
  284. @property(retain, nonatomic) UIFont *font;
  285. - (void)disableClearsOnInsertion;
  286. @property(nonatomic) BOOL clearsOnInsertion;
  287. - (float)shadowBlur;
  288. - (void)setShadowBlur:(float)arg1;
  289. - (struct CGSize)shadowOffset;
  290. - (void)setShadowOffset:(struct CGSize)arg1;
  291. - (id)shadowColor;
  292. - (void)setShadowColor:(id)arg1;
  293. @property(retain, nonatomic) UIColor *textColor;
  294. - (void)_updateTextColor;
  295. @property(copy, nonatomic) NSAttributedString *attributedText;
  296. - (void)_setAttributedText:(id)arg1 onFieldEditorAndSetCaretSelectionAfterText:(BOOL)arg2;
  297. - (void)_transferTextFieldPropertiesFromText:(id)arg1;
  298. - (void)_transferAttribute:(id)arg1 fromString:(id)arg2 andSetPropertyWith:(SEL)arg3 usingValueClass:(Class)arg4;
  299. @property(copy, nonatomic) NSString *text;
  300. - (void)finishedSettingTextOrAttributedText;
  301. - (id)searchText;
  302. - (BOOL)_hasContent;
  303. - (id)_attributedText;
  304. - (id)_text;
  305. @property(nonatomic, getter=isSecureTextEntry) BOOL secureTextEntry; // @dynamic secureTextEntry;
  306. - (void)_updateTextLabel;
  307. - (BOOL)respondsToSelector:(SEL)arg1;
  308. - (id)methodSignatureForSelector:(SEL)arg1;
  309. - (void)forwardInvocation:(id)arg1;
  310. - (id)textInputTraits;
  311. - (BOOL)_shouldSendContentChangedNotificationsIfOnlyMarkedTextChanged;
  312. - (id)_textLabelView;
  313. - (id)_placeholderLabel;
  314. - (id)_placeholderView;
  315. - (id)_placeholderColor;
  316. - (void)_setSystemBackgroundViewActive:(BOOL)arg1;
  317. - (BOOL)_fieldEditorAttached;
  318. - (Class)_systemBackgroundViewClass;
  319. - (void)_setRightViewOffset:(struct CGSize)arg1;
  320. - (struct CGSize)_rightViewOffset;
  321. - (void)_setLeftViewOffset:(struct CGSize)arg1;
  322. - (struct CGSize)_leftViewOffset;
  323. - (struct CGPoint)_scrollOffset;
  324. - (id)actualFont;
  325. - (float)actualMinimumFontSize;
  326. - (struct CGRect)adjustedCaretRectForCaretRect:(struct CGRect)arg1;
  327. - (void)_updateRTLStateForText:(id)arg1 updateAlignment:(BOOL)arg2;
  328. - (void)_setImplicitAlignment;
  329. - (void)_clearBackgroundViews;
  330. - (void)_updateBackgroundViewsAnimated:(BOOL)arg1;
  331. - (BOOL)_shouldEndEditing;
  332. - (void)layoutSubviews;
  333. - (struct CGRect)_prefixFrame;
  334. - (struct CGRect)_suffixFrame;
  335. - (void)updateConstraints;
  336. - (void)_setUpBaselineLayoutConstraints;
  337. - (struct CGRect)_frameForLabel:(id)arg1 inTextRect:(struct CGRect)arg2;
  338. - (void)_updateLabel;
  339. - (struct CGRect)_textRectExcludingButtonsForBounds:(struct CGRect)arg1;
  340. - (struct CGRect)_textRectForBounds:(struct CGRect)arg1 forEditing:(BOOL)arg2;
  341. - (BOOL)_isShowingPrefix;
  342. - (BOOL)_isShowingPlaceholder;
  343. - (BOOL)_showsRightView;
  344. - (BOOL)_showsLeftView;
  345. - (BOOL)_showsClearButtonWhenEmpty;
  346. - (BOOL)_showsClearButton:(BOOL)arg1;
  347. - (BOOL)_showsClearButtonWhenNonEmpty:(BOOL)arg1;
  348. - (void)_updateAtomBackground;
  349. - (BOOL)_showsAtomBackground;
  350. - (BOOL)_partsShouldBeMini;
  351. - (BOOL)_heightShouldBeMini;
  352. - (struct CGRect)_atomBackgroundViewFrame;
  353. - (void)_updateAutosizeStyleIfNeeded;
  354. - (void)_updateButtons;
  355. - (id)_clearButton;
  356. - (id)clearButton;
  357. - (id)_clearButtonImageForState:(unsigned int)arg1;
  358. - (void)_endedEditing;
  359. - (id)_style;
  360. - (id)_createCSSStyleDeclarationForWebView:(id)arg1;
  361. - (float)_marginTop;
  362. - (id)_copyFont:(id)arg1 newSize:(float)arg2 maxSize:(float)arg3;
  363. - (void)setFont:(id)arg1 fullFontSize:(float)arg2;
  364. - (id)hitTest:(struct CGPoint)arg1 withEvent:(id)arg2;
  365. - (void)touchesEnded:(id)arg1 withEvent:(id)arg2;
  366. - (void)touchesCancelled:(id)arg1 withEvent:(id)arg2;
  367. - (void)_resignFirstResponder;
  368. - (void)_windowBecameKey;
  369. - (BOOL)resignFirstResponder;
  370. - (void)_removeShortcutController;
  371. - (void)_removeDefinitionController;
  372. - (void)_becomeFirstResponder;
  373. - (void)_updatePlaceholderPosition;
  374. - (int)_currentTextAlignment;
  375. - (void)__resumeBecomeFirstResponder;
  376. - (void)_becomeFirstResponderAndMakeVisible;
  377. - (BOOL)_requiresKeyboardResetOnReload;
  378. - (id)_keyboardResponder;
  379. - (BOOL)canResignFirstResponder;
  380. - (BOOL)canBecomeFirstResponder;
  381. - (struct CGSize)sizeThatFits:(struct CGSize)arg1;
  382. - (struct CGSize)_intrinsicSizeWithinSize:(struct CGSize)arg1;
  383. - (id)viewForBaselineLayout;
  384. - (struct CGSize)_textSize;
  385. - (struct CGSize)_textSizeUsingFullFontSize:(BOOL)arg1;
  386. - (void)setAnimating:(BOOL)arg1;
  387. - (void)setBounds:(struct CGRect)arg1;
  388. - (void)setFrame:(struct CGRect)arg1;
  389. - (void)_sizeChanged:(BOOL)arg1;
  390. - (void)_setNeedsStyleRecalc;
  391. - (void)_clearStyle;
  392. - (void)dealloc;
  393. - (void)_encodeBackgroundColorWithCoder:(id)arg1;
  394. - (void)encodeWithCoder:(id)arg1;
  395. - (void)_populateArchivedSubviews:(id)arg1;
  396. - (id)initWithCoder:(id)arg1;
  397. - (id)initWithFrame:(struct CGRect)arg1;
  398. - (void)_invalidateBaselineLayoutConstraints;
  399. - (id)_scriptingInfo;
  400. - (void)decodeRestorableStateWithCoder:(id)arg1;
  401. - (void)encodeRestorableStateWithCoder:(id)arg1;
  402. - (BOOL)isElementAccessibilityExposedToInterfaceBuilder;
  403. - (BOOL)isAccessibilityElementByDefault;
  404. // Remaining properties
  405. @property(nonatomic) int autocapitalizationType; // @dynamic autocapitalizationType;
  406. @property(nonatomic) int autocorrectionType; // @dynamic autocorrectionType;
  407. @property(nonatomic) BOOL enablesReturnKeyAutomatically; // @dynamic enablesReturnKeyAutomatically;
  408. @property(nonatomic) int keyboardAppearance; // @dynamic keyboardAppearance;
  409. @property(nonatomic) int keyboardType; // @dynamic keyboardType;
  410. @property(nonatomic) int returnKeyType; // @dynamic returnKeyType;
  411. @property(nonatomic) int spellCheckingType; // @dynamic spellCheckingType;
  412. @property(readonly, nonatomic) UIView *textInputView;
  413. @end

首先我们看它声明的方法,关于cursor 的函数,或者表示类似颜色设置的函数,一看之下,没有。这个时候我们注意到有一个函数是 - (id)textInputTraits;

字面意思上是文本输入特征的意思,这个很有可能是我们需要的设置光标的颜色,ok,现在我们开始写代码。

省略创建project的步骤,直接上代码

我们看到private 下面,有一行是标识color的,很可能这个就是我们找的光标样色的属性。同样我们看一下 UITextfieldTraits的头文件,找到我们需要调用的函数。

[html] view plaincopy
  1. /*
  2. *     Generated by class-dump 3.4 (64 bit).
  3. *
  4. *     class-dump is Copyright (C) 1997-1998, 2000-2001, 2004-2012 by Steve Nygard.
  5. */
  6. #import "NSObject.h"
  7. #import "NSCopying.h"
  8. #import "UITextInputTraits.h"
  9. #import "UITextInputTraits_Private.h"
  10. @class UIColor, UIImage;
  11. @interface UITextInputTraits : NSObject <UITextInputTraits, UITextInputTraits_Private, NSCopying>
  12. {
  13. int autocapitalizationType;
  14. int autocorrectionType;
  15. int spellCheckingType;
  16. unsigned int keyboardType:8;
  17. unsigned int keyboardAppearance:8;
  18. int returnKeyType;
  19. BOOL enablesReturnKeyAutomatically;
  20. BOOL secureTextEntry;
  21. struct __CFCharacterSet *textTrimmingSet;
  22. UIColor *insertionPointColor;
  23. UIColor *selectionBarColor;
  24. UIColor *selectionHighlightColor;
  25. UIImage *selectionDragDotImage;
  26. unsigned int insertionPointWidth;
  27. int textLoupeVisibility;
  28. int textSelectionBehavior;
  29. id textSuggestionDelegate;
  30. BOOL contentsIsSingleValue;
  31. BOOL acceptsEmoji;
  32. BOOL returnKeyGoesToNextResponder;
  33. BOOL acceptsFloatingKeyboard;
  34. BOOL acceptsSplitKeyboard;
  35. BOOL displaySecureTextUsingPlainText;
  36. BOOL learnsCorrections;
  37. int emptyContentReturnKeyType;
  38. int shortcutConversionType;
  39. BOOL suppressReturnKeyStyling;
  40. BOOL forceEnableDictation;
  41. BOOL useInterfaceLanguageForLocalization;
  42. BOOL deferBecomingResponder;
  43. }
  44. + (BOOL)keyboardTypeRequiresASCIICapable:(int)arg1;
  45. + (id)traitsByAdoptingTraits:(id)arg1;
  46. + (id)defaultTextInputTraits;
  47. @property(nonatomic) BOOL deferBecomingResponder; // @synthesize deferBecomingResponder;
  48. @property(nonatomic) BOOL useInterfaceLanguageForLocalization; // @synthesize useInterfaceLanguageForLocalization;
  49. @property(nonatomic) BOOL forceEnableDictation; // @synthesize forceEnableDictation;
  50. @property(nonatomic) BOOL suppressReturnKeyStyling; // @synthesize suppressReturnKeyStyling;
  51. @property(nonatomic) int shortcutConversionType; // @synthesize shortcutConversionType;
  52. @property(nonatomic) BOOL learnsCorrections; // @synthesize learnsCorrections;
  53. @property(nonatomic) BOOL displaySecureTextUsingPlainText; // @synthesize displaySecureTextUsingPlainText;
  54. @property(nonatomic) BOOL acceptsSplitKeyboard; // @synthesize acceptsSplitKeyboard;
  55. @property(nonatomic) BOOL acceptsFloatingKeyboard; // @synthesize acceptsFloatingKeyboard;
  56. @property(nonatomic) BOOL returnKeyGoesToNextResponder; // @synthesize returnKeyGoesToNextResponder;
  57. @property(nonatomic) int emptyContentReturnKeyType; // @synthesize emptyContentReturnKeyType;
  58. @property(nonatomic) BOOL acceptsEmoji; // @synthesize acceptsEmoji;
  59. @property(nonatomic) BOOL contentsIsSingleValue; // @synthesize contentsIsSingleValue;
  60. @property(nonatomic) int textSelectionBehavior; // @synthesize textSelectionBehavior;
  61. @property(nonatomic) int textLoupeVisibility; // @synthesize textLoupeVisibility;
  62. @property(nonatomic) unsigned int insertionPointWidth; // @synthesize insertionPointWidth;
  63. @property(retain, nonatomic) UIImage *selectionDragDotImage; // @synthesize selectionDragDotImage;
  64. @property(retain, nonatomic) UIColor *selectionHighlightColor; // @synthesize selectionHighlightColor;
  65. @property(retain, nonatomic) UIColor *selectionBarColor; // @synthesize selectionBarColor;
  66. @property(retain, nonatomic) UIColor *insertionPointColor; // @synthesize insertionPointColor;
  67. @property(nonatomic, getter=isSecureTextEntry) BOOL secureTextEntry; // @synthesize secureTextEntry;
  68. @property(nonatomic) BOOL enablesReturnKeyAutomatically; // @synthesize enablesReturnKeyAutomatically;
  69. @property(nonatomic) int returnKeyType; // @synthesize returnKeyType;
  70. @property(nonatomic) int keyboardAppearance; // @synthesize keyboardAppearance;
  71. @property(nonatomic) int keyboardType; // @synthesize keyboardType;
  72. @property(nonatomic) int spellCheckingType; // @synthesize spellCheckingType;
  73. @property(nonatomic) int autocorrectionType; // @synthesize autocorrectionType;
  74. @property(nonatomic) int autocapitalizationType; // @synthesize autocapitalizationType;
  75. - (BOOL)isEqual:(id)arg1;
  76. - (id)description;
  77. - (id)copyWithZone:(struct _NSZone *)arg1;
  78. - (void)takeTraitsFrom:(id)arg1;
  79. - (void)setToDefaultValues;
  80. - (void)dealloc;
  81. - (id)init;
  82. @property(nonatomic) id textSuggestionDelegate; // @dynamic textSuggestionDelegate;
  83. @property(nonatomic) struct __CFCharacterSet *textTrimmingSet; // @dynamic textTrimmingSet;
  84. - (id)dictionaryRepresentation;
  85. - (void)setToSecureValues;
  86. @end

我们找到一个property : insertionPointColor,字面意思上基本上确定这个就是我们要找的设置光标的函数。

经过尝试果然如此,现在贴上结果

各位看官,这次的关于私有api的分析就结束了,其实整个过程没这么顺利,只是我省掉了一些,本身这个做法我也没有用到项目中,而是选择一个开源的 项目,但是对于私有api的熟悉也体现一个程序员对于apple这套东西的熟悉,同时我们可以模仿私有的实现,做一些事情,但是不推荐大家直接使用私有 api。

转载于:https://www.cnblogs.com/frounk/p/4708815.html

ios中通过调试来使用私有api相关推荐

  1. Audio Unit: iOS中最底层最强大的音频控制API

    阅读的前提: Audio Session基础(Audio Session) Core Audio基本数据结构(Core Audio) 音视频基础知识 C/C++ 简单数据结构,函数使用 以下概念是文中 ...

  2. iOS 中的 timer 任务(寻找内存恶鬼之旅)

    前言 在 iOS 的开发过程中定时任务中能找到使用的场景,然而在 iOS 中默认的有关 timer 的 api 总是那么晦涩难用,而且暗坑不断,一旦遇上,会让你一脸懵逼,为了不再同一个地方跌倒两次,我 ...

  3. iOS私有Api检测

    个人原文博客地址: iOS私有Api检测 最近提交APP审核被苹果的审核人员是虐的不要不要的, 一直都说是使用了私有API 但是我使出了浑身解数, 也没找到自己写的代码里哪里用到了私有API, 最后网 ...

  4. class-dump获取iOS私有api

    转自:http://blog.csdn.net/sunyuanyang625/article/details/41440167 获取各类iOS私有api 安装工具class-dump 资源地址http ...

  5. class-dump导出iOS系统私有库以及简单的私有API调用

    前言 This is a command-line utility for examining the Objective-C runtim information stored in Mach-O ...

  6. iOS私有API检测扫描思路以及工具开发(Python3 + Django)

    不足之处 1.class-dump有些文件会报错,由于只支持OC runtime的方式获取,可执行文件是c或者swift都无法被dump 2.私有api在公开的Framework及私有的Private ...

  7. iOS buttonWithType:101 苹果私有api

    无意中发现,有人创建UIButton这样写 UIButton *previousButton = [UIButtonbuttonWithType:101]; 一看原来是私有api UIButton * ...

  8. 微信开发者工具模拟器、IOS真机调试、Android真机调试中Editor效果不一致问题

    问题环境: 1.微信开发者工具1.05.2110290(以下简称"工具") 2.真机调试1.0版本(不区分IOS与Android) 3.微信的editor component,用于 ...

  9. iOS 中使用 Mobile Installation 安装 IPA(使用iTunes/AppStore一样的安装API)

    iOS 中要安装一个程序,从用户角度看有三种: 1. 类似 Cydia 这种 DEB 的方式:直接安装到 /Applications 作为系统的APP,无法长按删除(不讨论CyDelete). 2. ...

最新文章

  1. jzoj3059-雕塑【容斥,数论】
  2. HDU6736 F.Forest Program(dfs找环)
  3. 微信公众号开发之授权获取用户信息
  4. 混合云架构,如何实现混合云落地?(上)
  5. VS2010 + OpenCL 1.1 @ Windows 7 + AMD HD6870
  6. layui按条件开启关闭编辑列
  7. Java 随机生成MAC地址
  8. 手动批量下载ts文件并合并
  9. 502 proxy error解决方法_Homebrew安装、卸载、可能的报错及解决方案_Mac
  10. 因式分解的常用三种方法
  11. P1195 口袋的天空
  12. Java开发 - Redis初体验
  13. Log日志存放到本地文件
  14. 一文总结十大经典排序算法(思维导图 + 动图演示 + 代码实现 C/C++/Python + 致命吐槽)
  15. 淘宝MySQL数据库高可用实现方案
  16. 【转】Jackson之多态反序列化(父类转不同子类)
  17. matlab bvp4c猜测解,bvp4c解边界值微分方程
  18. 山东师大计算机专业研究生,山东师范大学现代教育技术(专硕)专业考研难度分析-专业排名-难度大小...
  19. PRE_LOAD+putenv
  20. 金蝶k3服务器老是自动重新启动,金蝶K3:常见问题分析及解决方法

热门文章

  1. 福布斯2015中国非上市潜力企业100强
  2. 在ASP.NET MVC中使用IIS级别的URL Rewrite
  3. djano-cms学习笔计(一)
  4. IOS网络编程之http请求响应篇
  5. 计算机桌面文件管理窗口,隐藏Win10此电脑窗口的6个额外文件夹
  6. git rebase用法
  7. DPDK rte_mbuf
  8. leetcode算法题--二叉搜索树迭代器
  9. 在刷一道题,数字回文,以以前做过,刚好昨天也做了一个类似的题,数字反转,原理有点像-----9. Palindrome Number...
  10. sonar做代码检测时如何忽略一些代码文件