美文网首页iOS学习笔记iOS高阶UI相关iOS Developer
根据Label的内容,计算label的尺寸或者高度

根据Label的内容,计算label的尺寸或者高度

作者: Z了个L | 来源:发表于2016-07-22 17:46 被阅读252次

CGFloat nameX = CGRectGetMaxX(_iconFrame) + space;
CGFloat nameY = iconY;
NSDictionary *nameAtt = @{NSFontAttributeName : XMGNameFont};
// 知道文字,知道文字大小,求这段文字的尺寸
CGSize nameSize = [_name sizeWithAttributes:nameAtt];
_nameFrame = CGRectMake(nameX, nameY, nameSize.width, nameSize.height);


CGFloat textX = iconX;
CGFloat textY = CGRectGetMaxY(_iconFrame) + space;
CGFloat textW = width - 2 * space;
CGSize maxTextSize = CGSizeMake(textW, MAXFLOAT);
NSDictionary *textAtt = @{NSFontAttributeName : XMGTextFont};
// 知道文字,知道文字的宽度,求文字的高度
CGFloat textH = [_text boundingRectWithSize:maxTextSize options:NSStringDrawingUsesLineFragmentOrigin attributes:textAtt context:nil].size.height;
_textFrame = CGRectMake(textX, textY, textW, textH);


相关文章

网友评论

    本文标题:根据Label的内容,计算label的尺寸或者高度

    本文链接:https://www.haomeiwen.com/subject/fnmijttx.html