ios - placeholder is not taking NSTextAlignmentNatural -


i have app have uitextfield.

my app english - arabic app.

now have below.

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 see, have set alignment text nstextalignmentnatural. did because if keyboard arabic (& app english or arabic), want textfield start right side.

with when changed keyboard english, text field start ltr & if change keyboard arabic, textfield start rtl. however, placeholder have @ left.

any way how can make placeholder alignment based on app language?

to tackle issue, below did...

  1. in .pch add below

    #define mydirection001 ([localize(@"mylang") isequaltostring:@"en"]) ? nstextalignmentleft : nstextalignmentright

  2. then have code below.

    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; 

make sure delegate set going call delegates now.

  1. call delegate methods.

    - (bool)textfieldshouldbeginediting:(uitextfield *)textfield {     textfield.textalignment = nstextalignmentnatural;         return yes; }  - (bool)textfieldshouldreturn:(uitextfield *)textfield{     textfield.textalignment = (textfield.text.length==0) ? mydirection001 : nstextalignmentnatural;     return yes; } 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -