根据文字动态调整按钮(UIButton)宽度

2016-12-27  本文已影响294人  LTSimple

NSString *content = button.titleLabel.text;
UIFont *font = button.titleLabel.font;
CGSize size = CGSizeMake(MAXFLOAT, 30.0f);
CGSize buttonSize = [content boundingRectWithSize:size
options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
attributes:@{ NSFontAttributeName:font}
context:nil].size;

根据buttonSize去设置button的size

上一篇下一篇

猜你喜欢

热点阅读