Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change cursor style of UITextView?

When editing in a UITextView, I know how to change the cursor color by setting tintColor. Is there any why to change cursor to another style?

For example: a blinking fixed-width box. or a underline "_"

like image 298
Strong84 Avatar asked Nov 26 '25 07:11

Strong84


1 Answers

I found a solution:

1.Subclassing UITextView

2.Overwrite caretRectForPosition: method

- (CGRect)caretRectForPosition:(UITextPosition *)position
{
    CGRect myRect = [super caretRectForPosition:position];
    myRect.size.width = 5; // Modify the width of the caret
    myRect.size.height = 5; // Modify the height of the caret

    return myRect;
}
like image 154
Strong84 Avatar answered Nov 30 '25 04:11

Strong84



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!