首页 > 其他 > 详细

文本自适应高度(含适配iOS7)

时间:2014-02-26 01:53:09      阅读:429      评论:0      收藏:0      [点我收藏+]

遇到了需要自适应高度,在iOS6好用的代码在iOS7上被废弃了,下面是在stackoverflow收集到的解决办法。

bubuko.com,布布扣
                if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {
                    CGSize size = CGSizeMake(230,9999);
                    CGRect textRect = [specialityObj.name
                                       boundingRectWithSize:size
                                       options:NSStringDrawingUsesLineFragmentOrigin
                                       attributes:@{NSFontAttributeName:[UIFont fontWithName:[AppHandlers zHandler].fontName size:14]}
                                       context:nil];
                    total_height = total_height + textRect.size.height;
                }
                else {
                    CGSize maximumLabelSize = CGSizeMake(230,9999);
                    expectedLabelSize = [specialityObj.name sizeWithFont:[UIFont fontWithName:[AppHandlers zHandler].fontName size:14] constrainedToSize:maximumLabelSize lineBreakMode:UILineBreakModeWordWrap]; //iOS 6 and previous.
                    total_height = total_height + expectedLabelSize.height;
                }
bubuko.com,布布扣

文本自适应高度(含适配iOS7)

原文:http://www.cnblogs.com/marvindev/p/adaptive.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!