1. TextView/TextField自定义光标的颜色
方法1:
这种方法将影响所有TextField。
方法2:
如果在InterfaceBuilder中修改View的TintColor属性并不好用。
参考http://stackoverflow.com/questions/11606007/change-uitextfield-and-uitextview-cursor-caret-color
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; }