更改默认光标图标 UITextView iOS? [英] change default cursor icon UITextView iOS?
本文介绍了更改默认光标图标 UITextView iOS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要更改UITextView
的默认光标图标.我想将其更改为圆形图标而不是如下所示的线条.任何帮助表示赞赏.提前致谢.
I need to change default cursor icon of UITextView
. I want to change it as a circle icon instead of a line as shown below. Any help is appreciated. Thanks in advance.
推荐答案
无法更改 textView 的原始插入符号.
It is not possible to change textView's original caret.
你应该定制一个.为此,创建一个 UITextView 的子类:
You should make your custom one. To do so make a subclass of UITextView:
@interface CustomTextView()
@property (strong, nonatomic) UIImageView *caretImageView;
@end
@implementation CustomTextView
- (void)awakeFromNib
{
[super awakeFromNib];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(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
selector:@selector(blink)
userInfo:nil
repeats:YES];
}
- (void)blink
{
self.caretImageView.alpha = !(BOOL)self.caretImageView.alpha;
}
// Hiding original caret
- (CGRect)caretRectForPosition:(UITextPosition *)position
{
return CGRectZero;
}
// Repositioning caretImageView everytime when text did change
- (void)textDidChange:(NSNotification *)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
这篇关于更改默认光标图标 UITextView iOS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文