ios中通過調試來使用私有api

       iOS不允許使用ios私有api,使用私有api可以獲得意想不到的效果 ,同時使用私有api是一個程序員的技術體現之一。至於怎麼通過apple的審覈,其實是有些辦法的,但是不屬於今天討論的範圍。私有api可以通過dump頭文件獲得,也可以去github clone一份現成的,但是還是推薦自己去dump。但是我們今天不是討論,如何使用dump到的api,而是通過一個例子來討論如何通過查看頭文件使用私有api。

      我們以UITextfield爲例,其實這是個比較簡單的控件,有一個藍色輸入的光標,可以在你輸入的時候隱藏或者顯示,但是並沒有給我們提供改變光標顏色的接口,這個時候我們如果要改變光標的顏色,必然要使用私有api(或者通過比較囉嗦的辦法來做這這件事情)。
     我們首先需要dump一包頭文件,如何class-dump,不是我們今天討論的要點,現在我們貼上UITextfield的頭文件。如果你覺得很長,直接拖到最後面。


/*
 *     Generated by class-dump 3.4 (64 bit).
 *
 *     class-dump is Copyright (C) 1997-1998, 2000-2001, 2004-2012 by Steve Nygard.
 */

#import <UIKit/UIControl.h>

#import "NSCoding.h"
#import "UIPopoverControllerDelegate.h"
#import "UITextInput.h"

@class NSArray, NSAttributedString, NSDictionary, NSString, UIButton, UIColor, UIFont, UIImage, UIImageView, UILabel, UITextFieldAtomBackgroundView, UITextFieldBackgroundView, UITextFieldBorderView, UITextFieldLabel, UITextInputTraits, UITextInteractionAssistant, UITextPosition, UITextRange, UIView, _UIBaselineLayoutStrut, _UITextServiceSession;

@interface UITextField : UIControl <UIPopoverControllerDelegate, UITextInput, NSCoding>
{
    NSAttributedString *_text;
    UIColor *_textColor;
    int _borderStyle;
    float _minimumFontSize;
    id _delegate;
    UIImage *_background;
    UIImage *_disabledBackground;
    int _clearButtonMode;
    UIView *_leftView;
    int _leftViewMode;
    UIView *_rightView;
    int _rightViewMode;
    UITextInputTraits *_traits;
    UITextInputTraits *_nonAtomTraits;
    float _fullFontSize;
    float _paddingLeft;
    float _paddingTop;
    float _paddingRight;
    float _paddingBottom;
    NSString *_textFont;
    struct _NSRange _selectionRange;
    int _scrollXOffset;
    int _scrollYOffset;
    float _progress;
    NSString *_style;
    UIButton *_clearButton;
    struct CGSize _clearButtonOffset;
    struct CGSize _leftViewOffset;
    struct CGSize _rightViewOffset;
    UITextFieldBorderView *_backgroundView;
    UITextFieldBorderView *_disabledBackgroundView;
    UITextFieldBackgroundView *_systemBackgroundView;
    UITextFieldLabel *_textLabel;
    UITextFieldLabel *_placeholderLabel;
    UITextFieldLabel *_suffixLabel;
    UITextFieldLabel *_prefixLabel;
    UIImageView *_iconView;
    UILabel *_label;
    float _labelOffset;
    UITextInteractionAssistant *_interactionAssistant;
    UIView *_inputView;
    UIView *_inputAccessoryView;
    UITextFieldAtomBackgroundView *_atomBackgroundView;
    UIColor *_shadowColor;
    struct CGSize _shadowOffset;
    float _shadowBlur;
    struct {
        unsigned int secureTextChanged:1;
        unsigned int guard:1;
        unsigned int delegateRespondsToHandleKeyDown:1;
        unsigned int verticallyCenterText:1;
        unsigned int isAnimating:4;
        unsigned int inactiveHasDimAppearance:1;
        unsigned int becomesFirstResponderOnClearButtonTap:1;
        unsigned int clearsOnBeginEditing:1;
        unsigned int clearsPlaceholderOnBeginEditing:1;
        unsigned int adjustsFontSizeToFitWidth:1;
        unsigned int fieldEditorAttached:1;
        unsigned int canBecomeFirstResponder:1;
        unsigned int shouldSuppressShouldBeginEditing:1;
        unsigned int inResignFirstResponder:1;
        unsigned int undoDisabled:1;
        unsigned int contentsRTL:1;
        unsigned int explicitAlignment:1;
        unsigned int implementsCustomDrawing:1;
        unsigned int needsClearing:1;
        unsigned int suppressContentChangedNotification:1;
        unsigned int allowsEditingTextAttributes:1;
        unsigned int usesAttributedText:1;
        unsigned int backgroundViewState:2;
        unsigned int clearsOnInsertion:1;
    } _textFieldFlags;
    _UITextServiceSession *_definitionSession;
    _UITextServiceSession *_learnSession;
    BOOL _deferringBecomeFirstResponder;
    BOOL _avoidBecomeFirstResponder;
    BOOL _setSelectionRangeAfterFieldEditorIsAttached;
    NSArray *_baselineLayoutConstraints;
    _UIBaselineLayoutStrut *_baselineLayoutLabel;
}

@property(retain) UIView *inputView; // @synthesize inputView=_inputView;
@property(nonatomic) int rightViewMode; // @synthesize rightViewMode=_rightViewMode;
@property(retain, nonatomic) UIView *rightView; // @synthesize rightView=_rightView;
@property(nonatomic) int leftViewMode; // @synthesize leftViewMode=_leftViewMode;
@property(retain, nonatomic) UIView *leftView; // @synthesize leftView=_leftView;
@property(nonatomic) int clearButtonMode; // @synthesize clearButtonMode=_clearButtonMode;
@property(retain, nonatomic) UIImage *disabledBackground; // @synthesize disabledBackground=_disabledBackground;
@property(retain, nonatomic) UIImage *background; // @synthesize background=_background;
@property(nonatomic) id <UITextFieldDelegate> delegate; // @synthesize delegate=_delegate;
@property(nonatomic) float minimumFontSize; // @synthesize minimumFontSize=_minimumFontSize;
@property(nonatomic) int borderStyle; // @synthesize borderStyle=_borderStyle;
@property(retain, nonatomic, setter=_setBaselineLayoutLabel:) _UIBaselineLayoutStrut *_baselineLayoutLabel; // @synthesize _baselineLayoutLabel;
@property(copy, nonatomic, setter=_setBaselineLayoutConstraints:) NSArray *_baselineLayoutConstraints; // @synthesize _baselineLayoutConstraints;
- (void)setSelectionGranularity:(int)arg1;
- (int)selectionGranularity;
- (id)_findWebViewWordBoundaryFromPosition:(id)arg1;
@property(nonatomic) int selectionAffinity;
- (id)characterRangeAtPoint:(struct CGPoint)arg1;
- (id)closestPositionToPoint:(struct CGPoint)arg1 withinRange:(id)arg2;
- (id)closestPositionToPoint:(struct CGPoint)arg1;
- (struct CGRect)caretRectForPosition:(id)arg1;
- (struct CGRect)firstRectForRange:(id)arg1;
- (void)setBaseWritingDirection:(int)arg1 forRange:(id)arg2;
- (int)baseWritingDirectionForPosition:(id)arg1 inDirection:(int)arg2;
- (id)characterRangeByExtendingPosition:(id)arg1 inDirection:(int)arg2;
- (id)positionWithinRange:(id)arg1 farthestInDirection:(int)arg2;
@property(readonly, nonatomic) id <UITextInputTokenizer> tokenizer;
@property(nonatomic) id <UITextInputDelegate> inputDelegate;
- (int)offsetFromPosition:(id)arg1 toPosition:(id)arg2;
- (int)comparePosition:(id)arg1 toPosition:(id)arg2;
- (id)positionFromPosition:(id)arg1 inDirection:(int)arg2 offset:(int)arg3;
- (id)positionFromPosition:(id)arg1 offset:(int)arg2;
- (id)textRangeFromPosition:(id)arg1 toPosition:(id)arg2;
@property(readonly, nonatomic) UITextPosition *endOfDocument;
@property(readonly, nonatomic) UITextPosition *beginningOfDocument;
- (void)unmarkText;
- (void)setMarkedText:(id)arg1 selectedRange:(struct _NSRange)arg2;
@property(copy, nonatomic) NSDictionary *markedTextStyle;
@property(readonly, nonatomic) UITextRange *markedTextRange;
@property(copy) UITextRange *selectedTextRange;
- (void)replaceRange:(id)arg1 withText:(id)arg2;
- (id)textInRange:(id)arg1;
- (BOOL)hasText;
- (id)metadataDictionariesForDictationResults;
- (struct CGRect)frameForDictationResultPlaceholder:(id)arg1;
- (void)removeDictationResultPlaceholder:(id)arg1 willInsertResult:(BOOL)arg2;
- (id)insertDictationResultPlaceholder;
- (void)insertDictationResult:(id)arg1 withCorrectionIdentifier:(id)arg2;
- (void)insertText:(id)arg1;
- (void)deleteBackward;
- (id)_proxyTextInput;
- (BOOL)canPerformAction:(SEL)arg1 withSender:(id)arg2;
- (BOOL)inPopover;
- (void)_promptForReplace:(id)arg1;
- (void)replace:(id)arg1;
- (void)_showTextStyleOptions:(id)arg1;
- (void)toggleUnderline:(id)arg1;
- (void)toggleItalics:(id)arg1;
- (void)toggleBoldface:(id)arg1;
- (void)makeTextWritingDirectionLeftToRight:(id)arg1;
- (void)makeTextWritingDirectionRightToLeft:(id)arg1;
- (void)selectAll:(id)arg1;
- (void)select:(id)arg1;
- (void)paste:(id)arg1;
- (void)_addShortcut:(id)arg1;
- (void)_selectionMayChange:(id)arg1;
- (BOOL)_isDisplayingReferenceLibraryViewController;
- (void)_define:(id)arg1;
- (void)copy:(id)arg1;
- (void)cut:(id)arg1;
- (id)webView;
- (struct CGPoint)constrainedPoint:(struct CGPoint)arg1;
- (unsigned int)offsetInMarkedTextForSelection:(id)arg1;
- (struct CGRect)closestCaretRectInMarkedTextRangeForPoint:(struct CGPoint)arg1;
- (id)selectedAttributedText;
- (id)selectedText;
- (id)selectionRectsForRange:(id)arg1;
- (struct CGRect)_selectionClipRect;
- (id)interactionAssistant;
- (id)selectionView;
- (void)cancelAutoscroll;
- (void)startAutoscroll:(struct CGPoint)arg1;
- (BOOL)hasSelection;
- (id)_fieldEditor;
- (void)endSelectionChange;
- (void)beginSelectionChange;
- (BOOL)isEditable;
- (id)undoManager;
- (int)atomStyle;
- (void)setAtomStyle:(int)arg1;
- (BOOL)drawsAsAtom;
- (void)setDrawsAsAtom:(BOOL)arg1;
- (void)setClearButtonOffset:(struct CGSize)arg1;
- (void)_clearButtonClicked:(id)arg1;
- (BOOL)isUndoEnabled;
- (void)setUndoEnabled:(BOOL)arg1;
- (void)setTextCentersVertically:(BOOL)arg1;
- (void)setTextCentersHorizontally:(BOOL)arg1;
- (void)setLabel:(id)arg1;
- (id)textLabel;
- (void)setLabelOffset:(float)arg1;
- (BOOL)hasMarkedText;
- (void)setProgress:(float)arg1;
- (struct CGRect)iconRect;
- (void)setBecomesFirstResponderOnClearButtonTap:(BOOL)arg1;
- (struct CGSize)clearButtonOffset;
- (void)setIcon:(id)arg1;
- (unsigned int)characterOffsetAtPoint:(struct CGPoint)arg1;
- (void)setSelectionRange:(struct _NSRange)arg1;
- (struct _NSRange)selectionRange;
- (void)clearText;
- (void)layoutTilesNow;
- (void)_resetSelectionUI;
- (void)_clearSelectionUI;
- (void)selectAll;
- (void)setEnabled:(BOOL)arg1;
- (void)_setEnabled:(BOOL)arg1 animated:(BOOL)arg2;
- (void)setInactiveHasDimAppearance:(BOOL)arg1;
- (void)setTextFont:(id)arg1;
- (float)paddingRight;
- (void)setPaddingRight:(float)arg1;
- (float)paddingBottom;
- (void)setPaddingBottom:(float)arg1;
- (float)paddingTop;
- (void)setPaddingTop:(float)arg1;
- (float)paddingLeft;
- (void)setPaddingLeft:(float)arg1;
- (void)setPaddingTop:(float)arg1 paddingLeft:(float)arg2;
- (void)drawBorder:(struct CGRect)arg1;
- (void)drawRect:(struct CGRect)arg1;
- (BOOL)_canDrawContent;
- (BOOL)_implementsCustomDrawing;
- (struct CGRect)editRect;
- (struct CGRect)textRect;
- (struct CGRect)clearButtonRect;
- (void)setClearButtonStyle:(int)arg1;
- (void)setTextAutorresizesToFit:(BOOL)arg1;
- (void)setAutoresizesTextToFit:(BOOL)arg1;
- (id)documentFragmentForPasteboardItemAtIndex:(int)arg1;
- (id)_dictationInterpretations;
- (id)supportedPasteboardTypesForCurrentSelection;
- (BOOL)fieldEditor:(id)arg1 shouldReplaceWithText:(id)arg2;
- (BOOL)fieldEditor:(id)arg1 shouldInsertText:(id)arg2 replacingRange:(struct _NSRange)arg3;
- (void)fieldEditorDidChangeSelection:(id)arg1;
- (struct _NSRange)fieldEditor:(id)arg1 willChangeSelectionFromCharacterRange:(struct _NSRange)arg2 toCharacterRange:(struct _NSRange)arg3;
- (void)selectAllFromFieldEditor:(id)arg1;
- (void)fieldEditorDidChange:(id)arg1;
- (id)customOverlayContainer;
- (void)keyboardInputChangedSelection:(id)arg1;
- (BOOL)keyboardInputChanged:(id)arg1;
- (BOOL)keyboardInputShouldDelete:(id)arg1;
- (BOOL)keyboardInput:(id)arg1 shouldReplaceTextInRange:(struct _NSRange)arg2 replacementText:(id)arg3;
- (BOOL)keyboardInput:(id)arg1 shouldInsertText:(id)arg2 isMarkedText:(BOOL)arg3;
- (void)_applicationResuming:(id)arg1;
- (void)willDetachFieldEditor:(id)arg1;
- (void)attachFieldEditor:(id)arg1;
- (void)willAttachFieldEditor:(id)arg1;
- (void)_drawTextInRect:(struct CGRect)arg1 forLabel:(id)arg2;
- (void)drawPrefixInRect:(struct CGRect)arg1;
- (void)drawSuffixInRect:(struct CGRect)arg1;
- (void)drawPlaceholderInRect:(struct CGRect)arg1;
- (void)drawTextInRect:(struct CGRect)arg1;
- (struct CGRect)rightViewRectForBounds:(struct CGRect)arg1;
- (struct CGRect)leftViewRectForBounds:(struct CGRect)arg1;
- (struct CGRect)_baselineLeftViewRectForBounds:(struct CGRect)arg1;
- (struct CGRect)clearButtonRectForBounds:(struct CGRect)arg1;
- (struct CGRect)editingRectForBounds:(struct CGRect)arg1;
- (struct CGRect)placeholderRectForBounds:(struct CGRect)arg1;
- (struct CGRect)textRectForBounds:(struct CGRect)arg1;
- (struct CGRect)borderRectForBounds:(struct CGRect)arg1;
@property(retain) UIView *inputAccessoryView;
@property(readonly, nonatomic, getter=isEditing) BOOL editing;
- (id)backgroundColor;
- (void)setBackgroundColor:(id)arg1;
@property(copy, nonatomic) NSDictionary *typingAttributes;
@property(nonatomic) BOOL allowsEditingTextAttributes;
@property(nonatomic) BOOL adjustsFontSizeToFitWidth;
- (void)setClearsPlaceholderOnBeginEditing:(BOOL)arg1;
- (BOOL)clearsPlaceholderOnBeginEditing;
@property(nonatomic) BOOL clearsOnBeginEditing;
- (void)_setPrefix:(id)arg1;
- (void)_setSuffix:(id)arg1 withColor:(id)arg2;
@property(copy, nonatomic) NSAttributedString *attributedPlaceholder;
@property(copy, nonatomic) NSString *placeholder;
- (void)createPlaceholderIfNecessary;
- (void)finishedSettingPlaceholder;
- (id)createTextLabelWithTextColor:(id)arg1;
- (void)_createBaselineLayoutLabelIfNecessary;
- (id)createPlaceholderLabelWithFont:(id)arg1 andTextAlignment:(int)arg2;
- (void)setContentVerticalAlignment:(int)arg1;
@property(nonatomic) int textAlignment;
@property(retain, nonatomic) UIFont *font;
- (void)disableClearsOnInsertion;
@property(nonatomic) BOOL clearsOnInsertion;
- (float)shadowBlur;
- (void)setShadowBlur:(float)arg1;
- (struct CGSize)shadowOffset;
- (void)setShadowOffset:(struct CGSize)arg1;
- (id)shadowColor;
- (void)setShadowColor:(id)arg1;
@property(retain, nonatomic) UIColor *textColor;
- (void)_updateTextColor;
@property(copy, nonatomic) NSAttributedString *attributedText;
- (void)_setAttributedText:(id)arg1 onFieldEditorAndSetCaretSelectionAfterText:(BOOL)arg2;
- (void)_transferTextFieldPropertiesFromText:(id)arg1;
- (void)_transferAttribute:(id)arg1 fromString:(id)arg2 andSetPropertyWith:(SEL)arg3 usingValueClass:(Class)arg4;
@property(copy, nonatomic) NSString *text;
- (void)finishedSettingTextOrAttributedText;
- (id)searchText;
- (BOOL)_hasContent;
- (id)_attributedText;
- (id)_text;
@property(nonatomic, getter=isSecureTextEntry) BOOL secureTextEntry; // @dynamic secureTextEntry;
- (void)_updateTextLabel;
- (BOOL)respondsToSelector:(SEL)arg1;
- (id)methodSignatureForSelector:(SEL)arg1;
- (void)forwardInvocation:(id)arg1;
- (id)textInputTraits;
- (BOOL)_shouldSendContentChangedNotificationsIfOnlyMarkedTextChanged;
- (id)_textLabelView;
- (id)_placeholderLabel;
- (id)_placeholderView;
- (id)_placeholderColor;
- (void)_setSystemBackgroundViewActive:(BOOL)arg1;
- (BOOL)_fieldEditorAttached;
- (Class)_systemBackgroundViewClass;
- (void)_setRightViewOffset:(struct CGSize)arg1;
- (struct CGSize)_rightViewOffset;
- (void)_setLeftViewOffset:(struct CGSize)arg1;
- (struct CGSize)_leftViewOffset;
- (struct CGPoint)_scrollOffset;
- (id)actualFont;
- (float)actualMinimumFontSize;
- (struct CGRect)adjustedCaretRectForCaretRect:(struct CGRect)arg1;
- (void)_updateRTLStateForText:(id)arg1 updateAlignment:(BOOL)arg2;
- (void)_setImplicitAlignment;
- (void)_clearBackgroundViews;
- (void)_updateBackgroundViewsAnimated:(BOOL)arg1;
- (BOOL)_shouldEndEditing;
- (void)layoutSubviews;
- (struct CGRect)_prefixFrame;
- (struct CGRect)_suffixFrame;
- (void)updateConstraints;
- (void)_setUpBaselineLayoutConstraints;
- (struct CGRect)_frameForLabel:(id)arg1 inTextRect:(struct CGRect)arg2;
- (void)_updateLabel;
- (struct CGRect)_textRectExcludingButtonsForBounds:(struct CGRect)arg1;
- (struct CGRect)_textRectForBounds:(struct CGRect)arg1 forEditing:(BOOL)arg2;
- (BOOL)_isShowingPrefix;
- (BOOL)_isShowingPlaceholder;
- (BOOL)_showsRightView;
- (BOOL)_showsLeftView;
- (BOOL)_showsClearButtonWhenEmpty;
- (BOOL)_showsClearButton:(BOOL)arg1;
- (BOOL)_showsClearButtonWhenNonEmpty:(BOOL)arg1;
- (void)_updateAtomBackground;
- (BOOL)_showsAtomBackground;
- (BOOL)_partsShouldBeMini;
- (BOOL)_heightShouldBeMini;
- (struct CGRect)_atomBackgroundViewFrame;
- (void)_updateAutosizeStyleIfNeeded;
- (void)_updateButtons;
- (id)_clearButton;
- (id)clearButton;
- (id)_clearButtonImageForState:(unsigned int)arg1;
- (void)_endedEditing;
- (id)_style;
- (id)_createCSSStyleDeclarationForWebView:(id)arg1;
- (float)_marginTop;
- (id)_copyFont:(id)arg1 newSize:(float)arg2 maxSize:(float)arg3;
- (void)setFont:(id)arg1 fullFontSize:(float)arg2;
- (id)hitTest:(struct CGPoint)arg1 withEvent:(id)arg2;
- (void)touchesEnded:(id)arg1 withEvent:(id)arg2;
- (void)touchesCancelled:(id)arg1 withEvent:(id)arg2;
- (void)_resignFirstResponder;
- (void)_windowBecameKey;
- (BOOL)resignFirstResponder;
- (void)_removeShortcutController;
- (void)_removeDefinitionController;
- (void)_becomeFirstResponder;
- (void)_updatePlaceholderPosition;
- (int)_currentTextAlignment;
- (void)__resumeBecomeFirstResponder;
- (void)_becomeFirstResponderAndMakeVisible;
- (BOOL)_requiresKeyboardResetOnReload;
- (id)_keyboardResponder;
- (BOOL)canResignFirstResponder;
- (BOOL)canBecomeFirstResponder;
- (struct CGSize)sizeThatFits:(struct CGSize)arg1;
- (struct CGSize)_intrinsicSizeWithinSize:(struct CGSize)arg1;
- (id)viewForBaselineLayout;
- (struct CGSize)_textSize;
- (struct CGSize)_textSizeUsingFullFontSize:(BOOL)arg1;
- (void)setAnimating:(BOOL)arg1;
- (void)setBounds:(struct CGRect)arg1;
- (void)setFrame:(struct CGRect)arg1;
- (void)_sizeChanged:(BOOL)arg1;
- (void)_setNeedsStyleRecalc;
- (void)_clearStyle;
- (void)dealloc;
- (void)_encodeBackgroundColorWithCoder:(id)arg1;
- (void)encodeWithCoder:(id)arg1;
- (void)_populateArchivedSubviews:(id)arg1;
- (id)initWithCoder:(id)arg1;
- (id)initWithFrame:(struct CGRect)arg1;
- (void)_invalidateBaselineLayoutConstraints;
- (id)_scriptingInfo;
- (void)decodeRestorableStateWithCoder:(id)arg1;
- (void)encodeRestorableStateWithCoder:(id)arg1;
- (BOOL)isElementAccessibilityExposedToInterfaceBuilder;
- (BOOL)isAccessibilityElementByDefault;

// Remaining properties
@property(nonatomic) int autocapitalizationType; // @dynamic autocapitalizationType;
@property(nonatomic) int autocorrectionType; // @dynamic autocorrectionType;
@property(nonatomic) BOOL enablesReturnKeyAutomatically; // @dynamic enablesReturnKeyAutomatically;
@property(nonatomic) int keyboardAppearance; // @dynamic keyboardAppearance;
@property(nonatomic) int keyboardType; // @dynamic keyboardType;
@property(nonatomic) int returnKeyType; // @dynamic returnKeyType;
@property(nonatomic) int spellCheckingType; // @dynamic spellCheckingType;
@property(readonly, nonatomic) UIView *textInputView;

@end


首先我們看它聲明的方法,關於cursor 的函數,或者表示類似顏色設置的函數,一看之下,沒有。這個時候我們注意到有一個函數是 - (id)textInputTraits;

字面意思上是文本輸入特徵的意思,這個很有可能是我們需要的設置光標的顏色,ok,現在我們開始寫代碼。

省略創建project的步驟,直接上代碼




我們看到private 下面,有一行是標識color的,很可能這個就是我們找的光標樣色的屬性。同樣我們看一下 UITextfieldTraits的頭文件,找到我們需要調用的函數。

/*
 *     Generated by class-dump 3.4 (64 bit).
 *
 *     class-dump is Copyright (C) 1997-1998, 2000-2001, 2004-2012 by Steve Nygard.
 */

#import "NSObject.h"

#import "NSCopying.h"
#import "UITextInputTraits.h"
#import "UITextInputTraits_Private.h"

@class UIColor, UIImage;

@interface UITextInputTraits : NSObject <UITextInputTraits, UITextInputTraits_Private, NSCopying>
{
    int autocapitalizationType;
    int autocorrectionType;
    int spellCheckingType;
    unsigned int keyboardType:8;
    unsigned int keyboardAppearance:8;
    int returnKeyType;
    BOOL enablesReturnKeyAutomatically;
    BOOL secureTextEntry;
    struct __CFCharacterSet *textTrimmingSet;
    UIColor *insertionPointColor;
    UIColor *selectionBarColor;
    UIColor *selectionHighlightColor;
    UIImage *selectionDragDotImage;
    unsigned int insertionPointWidth;
    int textLoupeVisibility;
    int textSelectionBehavior;
    id textSuggestionDelegate;
    BOOL contentsIsSingleValue;
    BOOL acceptsEmoji;
    BOOL returnKeyGoesToNextResponder;
    BOOL acceptsFloatingKeyboard;
    BOOL acceptsSplitKeyboard;
    BOOL displaySecureTextUsingPlainText;
    BOOL learnsCorrections;
    int emptyContentReturnKeyType;
    int shortcutConversionType;
    BOOL suppressReturnKeyStyling;
    BOOL forceEnableDictation;
    BOOL useInterfaceLanguageForLocalization;
    BOOL deferBecomingResponder;
}

+ (BOOL)keyboardTypeRequiresASCIICapable:(int)arg1;
+ (id)traitsByAdoptingTraits:(id)arg1;
+ (id)defaultTextInputTraits;
@property(nonatomic) BOOL deferBecomingResponder; // @synthesize deferBecomingResponder;
@property(nonatomic) BOOL useInterfaceLanguageForLocalization; // @synthesize useInterfaceLanguageForLocalization;
@property(nonatomic) BOOL forceEnableDictation; // @synthesize forceEnableDictation;
@property(nonatomic) BOOL suppressReturnKeyStyling; // @synthesize suppressReturnKeyStyling;
@property(nonatomic) int shortcutConversionType; // @synthesize shortcutConversionType;
@property(nonatomic) BOOL learnsCorrections; // @synthesize learnsCorrections;
@property(nonatomic) BOOL displaySecureTextUsingPlainText; // @synthesize displaySecureTextUsingPlainText;
@property(nonatomic) BOOL acceptsSplitKeyboard; // @synthesize acceptsSplitKeyboard;
@property(nonatomic) BOOL acceptsFloatingKeyboard; // @synthesize acceptsFloatingKeyboard;
@property(nonatomic) BOOL returnKeyGoesToNextResponder; // @synthesize returnKeyGoesToNextResponder;
@property(nonatomic) int emptyContentReturnKeyType; // @synthesize emptyContentReturnKeyType;
@property(nonatomic) BOOL acceptsEmoji; // @synthesize acceptsEmoji;
@property(nonatomic) BOOL contentsIsSingleValue; // @synthesize contentsIsSingleValue;
@property(nonatomic) int textSelectionBehavior; // @synthesize textSelectionBehavior;
@property(nonatomic) int textLoupeVisibility; // @synthesize textLoupeVisibility;
@property(nonatomic) unsigned int insertionPointWidth; // @synthesize insertionPointWidth;
@property(retain, nonatomic) UIImage *selectionDragDotImage; // @synthesize selectionDragDotImage;
@property(retain, nonatomic) UIColor *selectionHighlightColor; // @synthesize selectionHighlightColor;
@property(retain, nonatomic) UIColor *selectionBarColor; // @synthesize selectionBarColor;
@property(retain, nonatomic) UIColor *insertionPointColor; // @synthesize insertionPointColor;
@property(nonatomic, getter=isSecureTextEntry) BOOL secureTextEntry; // @synthesize secureTextEntry;
@property(nonatomic) BOOL enablesReturnKeyAutomatically; // @synthesize enablesReturnKeyAutomatically;
@property(nonatomic) int returnKeyType; // @synthesize returnKeyType;
@property(nonatomic) int keyboardAppearance; // @synthesize keyboardAppearance;
@property(nonatomic) int keyboardType; // @synthesize keyboardType;
@property(nonatomic) int spellCheckingType; // @synthesize spellCheckingType;
@property(nonatomic) int autocorrectionType; // @synthesize autocorrectionType;
@property(nonatomic) int autocapitalizationType; // @synthesize autocapitalizationType;
- (BOOL)isEqual:(id)arg1;
- (id)description;
- (id)copyWithZone:(struct _NSZone *)arg1;
- (void)takeTraitsFrom:(id)arg1;
- (void)setToDefaultValues;
- (void)dealloc;
- (id)init;
@property(nonatomic) id textSuggestionDelegate; // @dynamic textSuggestionDelegate;
@property(nonatomic) struct __CFCharacterSet *textTrimmingSet; // @dynamic textTrimmingSet;
- (id)dictionaryRepresentation;
- (void)setToSecureValues;

@end

我們找到一個property : insertionPointColor,字面意思上基本上確定這個就是我們要找的設置光標的函數。

經過嘗試果然如此,現在貼上結果



各位看官,這次的關於私有api的分析就結束了,其實整個過程沒這麼順利,只是我省掉了一些,本身這個做法我也沒有用到項目中,而是選擇一個開源的項目,但是對於私有api的熟悉也體現一個程序員對於apple這套東西的熟悉,同時我們可以模仿私有的實現,做一些事情,但是不推薦大家直接使用私有api。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章