3

我有一个UITextView与 RTL 对齐。

如果用户输入文本并关闭键盘,则对齐保持 - RTL。

但如果用户选择空字符串,我将字符串更改为占位符,对齐方式翻转为 LTR。

我试图明确要求 RTL,但没有帮助。

-(void)cancelPad{
    [userTextView resignFirstResponder];
    userTextView.textAlignment = UITextAlignmentRight;
    userTextView.text = @"place holder text";
}

-(void)doneWithNumberPad{
    if ([userTextView.text isEqualToString:@""]) {
        [self cancelPad];
    }
    [userTextView resignFirstResponder];
    userTextView.textAlignment = UITextAlignmentRight;
}

有人有什么想法吗?

4

3 回答 3

1

最后我只是添加了一个带有占位符文本的标签。当键盘显示时,placeholderLabel 被隐藏。如果键盘以空文本消失,则 placeholderLabel 将再次显示。如果有更合适的解决方案,请不要犹豫在此处发布。

于 2012-07-17T08:28:57.283 回答
1

代替:

userTextView.text = ""

你应该把:

userTextView.text = [NSString stringWithFormat:@"\u202b"];

这是“开始 RTL”的 UTF-8 字符

于 2012-10-31T12:43:30.413 回答
0

首先:在 .h 文件中添加这个

UIViewController<UITextFieldDelegate>

将您的文本字段分配给此

userTextView.delegate =self;

然后使用此方法并将您的代码放入

-(BOOL) textFieldShouldBeginEditing:(UITextField *)textField{


 }     
-(BOOL)textFieldShouldEndEditing:(UITextField *)textField{

}
-(BOOL) textFieldShouldReturn:(UITextField *)textField{

}

例子 :

-(BOOL)textFieldShouldEndEditing:(UITextField *)textField{

if ([userTextView.text isEqualToString:@""]) {
    [self cancelPad];
}
[userTextView resignFirstResponder];
userTextView.textAlignment = UITextAlignmentRight;
}
于 2012-07-16T09:37:38.857 回答