2014-06-23 130 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

我不知道這是可能的。我不認爲蘋果公開了在文本視圖中繪製光標的代碼。