UITextField右对齐iOS 7

我有一个问题,当在iOS7上对齐一个UITextField时,当用户键入“空格”时,它不会马上出现.如果我键入另外一个字符空格出现.

在iOS 6中并没有发生

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

任何人都知道如何解决这个问题?

解决方法

-(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;
}

从文本中删除代码

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

从这个stackoverflow答案 – UITextField spacebar does not advance cursor in iOS 7

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...