In my iPad app, I noticed different behavior between iOS 6 and iOS 7 with UITextFields.
I create the UITextField as follows:
UIButton *theButton = (U
Fix right aligned text space removing by replacing space with non-breaking space
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
if (textField.textAlignment == NSTextAlignmentRight) {
NSString *text = [textField.text stringByReplacingCharactersInRange:range withString:string];
textField.text = [text stringByReplacingOccurrencesOfString:@" " withString:@"\u00a0"];
UITextPosition *startPos = [textField positionFromPosition:textField.beginningOfDocument offset:range.location + string.length];
UITextRange *textRange = [textField textRangeFromPosition:startPos toPosition:startPos];
textField.selectedTextRange = textRange;
return NO;
}
return YES;
}
And vice versa
- (void)textFieldDidEndEditing:(UITextField *)textField
{
// Replacing non-breaking spaces with spaces and remove obsolete data
NSString *textString = [[textField.text stringByReplacingOccurrencesOfString:@"\u00a0" withString:@" "] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
textField.text = textString;
}