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
网友评论