iOS: UIButton resize according to text length

后端 未结 14 909
你的背包
你的背包 2020-11-29 17:28

In interface builder, holding Command + = will resize a button to fit its text. I was wondering if this was possible to do programmatically before the

14条回答
  •  盖世英雄少女心
    2020-11-29 18:09

    The way to do this in code is:

    [button sizeToFit];
    

    If you are subclassing and want to add extra rules you can override:

    - (CGSize)sizeThatFits:(CGSize)size;
    

提交回复
热议问题