ios - Which UILabel method is invoked when I set text, and it resizes itself to fit? -


i have uilabel, created in universal storyboard, , have mentioned required constraints position other width. resizes per text set. fantastic! want.

problem starts here : has background color green color, color wrapping text tightly. believe making little wider can me. that, need know method of uilabel subclass invoked. can override , add additional width of 10 points.

bottomline: uilabel method invoked resizing label automatically after assign text?

the way looks :

enter image description here

unfortunately, don't have contentedgeinsets property can set on uilabel (as have on uibutton). if want auto layout continue make height , width constraints itself, make subclass of uilabel , override intrinsiccontentsize , sizethatfits achieve want.

so, like:

- (cgsize) intrinsiccontentsize {     return [self addhorizontalpadding:[super intrinsiccontentsize]]; }  - (cgsize)sizethatfits:(cgsize)size {     return [self addhorizontalpadding:[super intrinsiccontentsize]]; }  - (cgsize)addhorizontalpadding:(cgsize)size {     return cgsizemake(size.width + (2*ksomehorizontalpaddingvalue), size.height); } 

note touches horizontal padding, can modified add vertical padding well.


Comments