自动调整文字高度With what should I replace the deprecated sizeWithFont:contrainedToSize:lineBreakMode method?
自动调整文字的高度:
ios 2.0 ~ 7.0以下:
UILabel *orgnizationLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, self.cellImageView.frame.size.height + 5, self.cellImageView.frame.size.width, 0)];
self.nameLabel = orgnizationLabel;
self.nameLabel.text = @"富力桃园幼儿园管理员";
self.nameLabel.textAlignment = NSTextAlignmentLeft;
self.nameLabel.font = [UIFont systemFontOfSize:16.0];
self.nameLabel.numberOfLines = 0;
self.nameLabel.lineBreakMode = NSLineBreakByWordWrapping;
self.nameLabel.textColor = [UIColor colorWithRed:68/255.0f green:153/255.0f blue:181/255.0f alpha:1.0];
CGRect labelFrameN = self.nameLabel.frame;
labelFrameN.size = [self.nameLabel.text sizeWithFont:self.nameLabel.font
constrainedToSize:CGSizeMake(self.nameLabel.frame.size.width, CGFLOAT_MAX)
lineBreakMode:self.nameLabel.lineBreakMode];
self.nameLabel.frame = labelFrameN;
7.0以及以后:
CGRect labelFrameN = self.nameLabel.frame;
NSDictionary *stringAttributes = [NSDictionary dictionaryWithObject:self.nameLabel.font forKey: NSFontAttributeName];
labelFrameN.size = [self.nameLabel.text boundingRectWithSize:CGSizeMake(self.nameLabel.frame.size.width, CGFLOAT_MAX)
options:NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesLineFragmentOrigin
attributes:stringAttributes context:nil].size;
self.nameLabel.frame = labelFrameN;