如何更改UITextView的光标样式?

3

在编辑UITextView时,我知道可以通过设置tintColor来更改光标颜色。但是否有办法将光标更改为其他样式呢?

例如:一个闪烁的固定宽度框或者下划线“_”

1个回答

4
我找到了一个解决方案:
1. 继承UITextView类
2. 重写caretRectForPosition:方法
- (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;
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接