iOS: UIButton resize according to text length

后端 未结 14 836
你的背包
你的背包 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:26

    If your button was made with Interface Builder, and you're changing the title in code, you can do this:

    [self.button setTitle:@"Button Title" forState:UIControlStateNormal];
    [self.button sizeToFit];
    

提交回复
热议问题