您的位置:首页 > 其它

根据文字内容确定控件尺寸

2016-01-07 15:46 344 查看
// 自适应字体宽度

- (CGSize)customSizeWithFont:(UIFont *)font

{

CGSize size = [selfsizeWithAttributes:@{NSFontAttributeName:font}];

return size;

}

// 根据内容计算 Label 高度

- (CGFloat)adjustHeightWithContent:(NSString *)content

{

CGRect contentBounds = [content
boundingRectWithSize:CGSizeMake(kScreenWidth -
kEdgeInRegisterTreaty *
2,1000)

options:NSStringDrawingUsesLineFragmentOrigin

attributes:[NSDictionary

dictionaryWithObject:

[RMUtils
defaultFont]

forKey:NSFontAttributeName]
context:nil];

return contentBounds.size.height +
5;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: