1. 程式人生 > >IOS根據文字計算laber的行數與長度

IOS根據文字計算laber的行數與長度

計算行數

CGFloat labelHeight = [self.content sizeThatFits:CGSizeMake(self.content.frame.size.width, MAXFLOAT)].height;

 NSNumber *count = @((labelHeight) / self.content.font.lineHeight);

計算長度

- (CGSize)getSizeRectMakeText:(NSString *)type addTextSize:(CGSize)text addFontDic:(NSDictionary *)dic{

CGRect

temp = [type boundingRectWithSize:text options:NSStringDrawingUsesLineFragmentOriginattributes:dic context:nil];

return temp.size;

}