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...
in .pch add below
#define mydirection001 ([localize(@"mylang") isequaltostring:@"en"]) ? nstextalignmentleft : nstextalignmentright
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.
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
Post a Comment