直接上代码 直接copy 过去用吧.
- (CGSize)stringCGSizeWithString:(NSString *)stringText Font:(CGFloat)font
{
CGSize stringTextSize = [stringText boundingRectWithSize:CGSizeMake(self.view.frame.size.width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:font]} context:nil].size;
return stringTextSize;
}