ios - UITextField doesn't scroll to the end after implementing textRectForBounds and editingRectForBounds in a subclass? -


i have uitextfield subclass implementing methods below:

- (cgrect)textrectforbounds:(cgrect)bounds {    return cgrectinset(bounds , 30, 7); }  -(cgrect) editingrectforbounds:(cgrect)bounds {   return cgrectinset(bounds , 30, 7); } 

because of these 2 methods, uitextfield doesn't scroll end when text entered gets bigger width of uitextfield. there solution this?

its not working because of font size of text have declared in uitextfield , cgrectinset applying. should per font size setting. example, font size of 14.0, change method below:

- (cgrect)textrectforbounds:(cgrect)bounds {     return cgrectinset(bounds , 30, 6); } -(cgrect) editingrectforbounds:(cgrect)bounds {     return cgrectinset(bounds , 30, 6); } 

the reason drawing rectangle of text. example, when set font size of uitextfield 14.0 requires @ least height of 18.0 adjust text in frame. needs 4 pixel around text, can overlay frame. due which, in case, condition not satisfying because far guess have adjusted font size 14.0 , default frame height of uitextfield 30.0 , edge masking of 7.0 each side means total 14.0. rect text returns 16.0 in turn blocks os updating text frame because outside of graphics context. hope clear. if resolves issue please accept answer. more answer follows:

- (cgrect)textrectforbounds:(cgrect)bounds { return cgrectinset(bounds , 30, (30 - self.font.pointsize - 4)/2); }  -(cgrect) editingrectforbounds:(cgrect)bounds {     return cgrectinset(bounds , 30, (30 - self.font.pointsize - 4)/2); } 

enjoy!


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -