2014-06-23 131 views

回答

2

无法更改textView的原始插页。

你应该让你的自定义一个。要做到这一点,做一个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 
+0

它引发了良好的感谢。 –

0

我不知道这是可能的。我不认为苹果公开了在文本视图中绘制光标的代码。