码迷,mamicode.com
首页 > 移动开发 > 详细

ios中通过调试来使用私有api

时间:2015-08-06 19:59:53      阅读:326      评论:0      收藏:0      [点我收藏+]

标签:

转自: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的头文件。如果你觉得很长,直接拖到最后面。


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


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

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

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


技术分享


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

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


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

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

技术分享


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


 

ios中通过调试来使用私有api

标签:

原文地址:http://www.cnblogs.com/frounk/p/4708815.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!