成都创新互联网站制作重庆分公司

iOS计算文字高度

#pragma mark-once 获取文字高度

成都创新互联公司服务项目包括红桥网站建设、红桥网站制作、红桥网页制作以及红桥网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,红桥网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到红桥省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!

- (CGSize)sizeWithmaxSize:(CGSize)size anText:(NSString *)anString

{

    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:anString];

    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc]init];

    [style setLineSpacing:6.0f];

    [attributedString addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, [anString length])];

    

        CGSize realSize = CGSizeZero;

    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {

        CGRect textRect = [anString boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:MyConsulDetailFrameFontSize],NSParagraphStyleAttributeName:style} context:nil];

        realSize = textRect.size;

    } else {

        realSize =  [anString sizeWithFont:[UIFont systemFontOfSize:MyConsulDetailFrameFontSize] maxSize:size lineBreakMode:NSLineBreakByCharWrapping];

    }

    realSize.width = ceilf(realSize.width);

    realSize.height = ceilf(realSize.height);

    return realSize;

}


当前名称:iOS计算文字高度
当前路径:http://cxhlcq.com/article/jcijcs.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部