ios - 更改默认光标图标 UITextView iOS?
<p><p>我需要更改 <code>UITextView</code> 的默认光标图标。我想将其更改为圆形图标而不是线条,如下所示。任何帮助表示赞赏。提前致谢。</p>
<p> <img src="/image/1Uwda.png" alt="enter image description here"/> </p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>无法更改 textView 的原始插入符号。 </p>
<p>您应该制作一个自定义的。为此,创建一个 UITextView 的子类:</p>
<pre><code>@interface CustomTextView()
@property (strong, nonatomic) UIImageView *caretImageView;
@end
@implementation CustomTextView
- (void)awakeFromNib
{
;
[ addObserver:self
selector:@selector(textDidChange:)
name:UITextViewTextDidChangeNotification
object:self];
self.caretImageView = // create and customize your caret view
//...
;
// 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
{
[ removeObserver:self name:UITextViewTextDidChangeNotification object:nil];
}
@end
</code></pre></p>
<p style="font-size: 20px;">关于ios - 更改默认光标图标 UITextView iOS?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/24364941/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/24364941/
</a>
</p>
页:
[1]