Blog

iOS ObjectiveC

UITextField cursor change notifications

If you need this feature, you will probably be a little bit annoyed, that only UITextViews do have this possibility. After the following web search you will be even more annoyed.

But what works for me is easy to implement and not hacky at all. Key-Value-Observing:

-(void)awakeFromNib {
    [self addObserver:self forKeyPath:@"selectedTextRange" options:0 context:nil];
}

-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
    [self notifyDelegateIfNecessary];
}

Tested in iOS 8.3.