Skip to content

Instantly share code, notes, and snippets.

@pyanfield
pyanfield / DetectTextFieldChanged.m
Created November 24, 2012 16:15
Get the current text in the UITextField when UITextField has been changed
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
NSString *currentStr;
if ((range.length == 0 && string.length > 0) || (range.length > 0 && string.length > 0)) {
// add the characters to textfield
NSString *firstHalfStr = [textField.text substringToIndex:range.location];
NSString *lastHalfStr = [textField.text substringFromIndex:(range.location + range.length)];
currentStr = [NSString stringWithFormat:@"%@%@%@",firstHalfStr,string,lastHalfStr];