Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITextField Right Alignment iOS 7

I have a problem, when Right Aligning a UITextField on iOS7, when the user types "Space" it wont appear right away. If I type another character the spaces appears.

In iOS 6 does is not happening

http://www.blogosfera.co.uk/2013/10/ios-7-whitespace-not-visible-to-uitextfield-with-right-alignment/

Anyone know how to fix this?

like image 886
apinho Avatar asked Dec 17 '13 16:12

apinho


1 Answers

-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    if (range.location == textField.text.length && [string isEqualToString:@" "]) {
        // ignore replacement string and add your own
        textField.text = [textField.text stringByAppendingString:@"\u00a0"];
        return NO;
    }
    // for all other cases, proceed with replacement
    return YES;
}

To remove the code from text

self.txtFirstName.text = [self.txtFirstName.text stringByReplacingOccurrencesOfString:@"\u00a0" withString:@" "];

FROM this stackoverflow answer - Right aligned UITextField spacebar does not advance cursor in iOS 7

like image 60
Akshit Zaveri Avatar answered Sep 21 '22 16:09

Akshit Zaveri