Placeholder does not accept NSTextAlignmentNatural

I have an application where I have it UITextField.

My application is an Anglo-Arabic application.

Now I have the following.

addPostVideoURL.backgroundColor = [UIColor clearColor];
addPostVideoURL.textAlignment = NSTextAlignmentNatural; <-- Setting alignment
addPostVideoURL.textColor = pGray_343434;
addPostVideoURL.placeholder = localize(@"videoURL");
[addPostVideoURL setValue:pGray_343434 forKeyPath:@"_placeholderLabel.textColor"];
addPostVideoURL.font = [self adjustDefaultFont:40];
addPostVideoURL.autocorrectionType = UITextAutocorrectionTypeNo;

If you see, I set the alignment text as NSTextAlignmentNatural. I did this because if the keyboard is Arabic (and my application is English or Arabic), I want the text box to start on the right side.

With this, when I changed the keyboard to English, the text field starts with LTR, and if I change the keyboard to Arabic, start the text field with RTL. However, the placeholder that I have is always on the left.

In any case, how can I do base alignment based on the application language?

+4
1

, - , ...

  • .pch

    #define myDirection001 ([localize(@"myLang") isEqualToString:@"en"]) ? NSTextAlignmentLeft : NSTextAlignmentRight

  • , .

    addPostVideoURL.backgroundColor = [UIColor clearColor];
    addPostVideoURL.textAlignment = myDirection001;
    addPostVideoURL.textColor = pGray_343434;
    addPostVideoURL.placeholder = localize(@"videoURL");
    [addPostVideoURL setValue:pGray_343434 forKeyPath:@"_placeholderLabel.textColor"];
    addPostVideoURL.font = [self adjustDefaultFont:40];
    addPostVideoURL.autocorrectionType = UITextAutocorrectionTypeNo;
    

, , .

  1. .

    - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
        textField.textAlignment = NSTextAlignmentNatural;    
        return YES;
    }
    
    - (BOOL)textFieldShouldReturn:(UITextField *)textField{
        textField.textAlignment = (textField.text.length==0) ? myDirection001 : NSTextAlignmentNatural;
        return YES;
    }
    
+1

Source: https://habr.com/ru/post/1625266/


All Articles