我需要更改 UITextView
的默认光标图标。我想将其更改为圆形图标而不是线条,如下所示。任何帮助表示赞赏。提前致谢。
无法更改 textView 的原始插入符号。
您应该制作一个自定义的。为此,创建一个 UITextView 的子类:
@interface CustomTextView()
@property (strong, nonatomic) UIImageView *caretImageView;
@end
@implementation CustomTextView
- (void)awakeFromNib
{
[super awakeFromNib];
[[NSNotificationCenter defaultCenter] addObserver:self
selectorselector(textDidChange
name:UITextViewTextDidChangeNotification
object:self];
self.caretImageView = // create and customize your caret view
//...
[self addSubview:self.caretImageView];
// Make careImageView to blink every 0.5 secs
[NSTimer scheduledTimerWithTimeInterval:0.5
target:self
selectorselector(blink)
userInfo:nil
repeats:YES];
}
- (void)blink
{
self.caretImageView.alpha = !(BOOL)self.caretImageView.alpha;
}
// Hiding original caret
- (CGRect)caretRectForPositionUITextPosition *)position
{
return CGRectZero;
}
// Repositioning caretImageView everytime when text did change
- (void)textDidChangeNSNotification *)note
{
CGPoint endPoint = // calculate the x and y coords of the text's end.
CGRect frame = self.caretImageView.frame;
frame.origin = endPoint;
self.caretImageView.frame = frame;
}
//
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:UITextViewTextDidChangeNotification object:nil];
}
@end
关于ios - 更改默认光标图标 UITextView iOS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24364941/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |