Disable blinking cursor in UITextField?

前端 未结 10 1161
日久生厌
日久生厌 2020-12-24 06:31

I\'ve followed the instructions here and succesfully set up a UITextField that gets updated with a UIDatePicker. However the cursor in the UITextField is blinking, which see

10条回答
  •  别那么骄傲
    2020-12-24 06:48

    You can add a BOOL cursorless property to UITextField in a category via associated objects.

    @interface UITextField (Cursorless)
    
    @property (nonatomic, assign) BOOL cursorless;
    
    @end
    

    Then use method swizzling to swizzle caretRectForPosition: with a method that toggles between CGRectZero and its default value using cursorless.

    This leads to a simple interface via a drop-in category. This is demonstrated in the following files.

    Simply drop them in and get the benefit of this simple interface

    UITextField category: https://github.com/rexmas/RexDK/blob/master/RexDK/UI/UITextField%2BRXCursorless.h https://github.com/rexmas/RexDK/blob/master/RexDK/UI/UITextField%2BRXCursorless.m

    Method Swizzling: https://github.com/rexmas/RexDK/blob/master/RexDK/Foundation/NSObject%2BRXRuntimeAdditions.h https://github.com/rexmas/RexDK/blob/master/RexDK/Foundation/NSObject%2BRXRuntimeAdditions.m

提交回复
热议问题