动态设置label的高度
2018-07-05 本文已影响0人
summerTa
CGSize titlethreeSize = [_mainLabel.text sizeWithFont:[UIFont systemFontOfSize:18] constrainedToSize:CGSizeMake(WIDTH-120*DJScaleScreenRation, MAXFLOAT) lineBreakMode:NSLineBreakByWordWrapping];
_mainLabel.frame = CGRectMake(20*DJScaleScreenRation, 40*DJScaleScreenRation, WIDTH-40*DJScaleScreenRation-120*DJScaleScreenRation, titlethreeSize.height);
- (CGSize)sizeWithString:(NSString*)str font:(UIFont*)font maxSize:(CGSize)maxSize
{
NSDictionary *dict = @{NSFontAttributeName : font};
// 如果将来计算的文字的范围超出了指定的范围,返回的就是指定的范围
// 如果将来计算的文字的范围小于指定的范围, 返回的就是真实的范围
CGSizesize = [strboundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil].size;
returnsize;
}