0

hi i want to resize my button width by text length when adding title right insets

i tried set Constant 100 and Priority 1000 and it work perfect but when i add image and right insets,

button title show like this

"apple...omputer"

and i tried this

button.invalidateIntrinsicContentSize()

and

button.sizeToFit()

still not work and still show "..." in my button text

and i tried to add width after set button title in viewdidload, but still not working

button.frame = CGRect(button.frame.origin.x, button.frame.origin.y, button.frame.width+50, button.frame.height)
saint
  • 103
  • 11
  • Does this answer your question? [Autolayout - intrinsic size of UIButton does not include title insets](https://stackoverflow.com/questions/17800288/autolayout-intrinsic-size-of-uibutton-does-not-include-title-insets) – Kirow Jul 24 '20 at 09:34
  • Could share a screenshot to understand what's the exact problem? – Ashutosh Mishra Jul 24 '20 at 09:45
  • hi @Kirow yes, thanks for your help, i solve my question by setting layout at trailing. thanks – saint Jul 24 '20 at 14:15
  • @Ashutosh , thanks , i solve my question! – saint Jul 24 '20 at 14:15

1 Answers1

1

Storyboard buttons

Resizing button because text became larger

Please look at screenshots above. You need to set your insets and set right constraints. Autolayout does it for you.

Victor
  • 50
  • 7
  • Thanks for ur answer, i set the layout greate than or equal at button width, now i got it. thans – saint Jul 24 '20 at 14:13