iOS 自定义TextView/TextField光标颜色、长度或高度

1. TextView/TextField光标颜色可通过设置tintColor属性进行修改:

self.textView.tintColor = [UIColor redColor];

 

2. TextView/TextField自定义光标长度或高度, 可通过重写父类方法caretRectForPosition:实现, 具体设置如下:

@interface CustomTextView : UITextView

重写父类方法:

- (CGRect)caretRectForPosition:(UITextPosition *)position
{
    CGRect originalRect = [super caretRectForPosition:position];
    
    originalRect.size.height = self.font.lineHeight + 2;
    originalRect.size.width = 5;
    
    return originalRect;
}

 

posted @ 2015-09-09 16:17  HappyPlane  阅读(4896)  评论(0编辑  收藏  举报