zoukankan      html  css  js  c++  java
  • UILabel自适应高、宽

    根据Label和字体大小自适应高度

    复制代码
    - (void)getHeightWithLabel:(UILabel *)label andFontSize:(CGFloat)size
    {
        label.numberOfLines = 0;
        NSMutableAttributedString *labelString = [[NSMutableAttributedString alloc] initWithString:label.text];
        [labelString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:size] range:NSMakeRange(0, [labelString length])];
        CGRect labelStringRect = [labelString boundingRectWithSize:CGSizeMake(self.view.frame.size.width-label.frame.origin.x*2, 9999) options:NSStringDrawingUsesLineFragmentOrigin context:nil];
        CGRect labelRect = label.frame;
        labelRect.size.height = labelStringRect.size.height;
        label.frame = labelRect;
        label.attributedText = labelString;
    }
    复制代码

    根据Label和字体大小自适应宽度

    复制代码
    - (void)getWidthWithLabel:(UILabel *)label andFontSize:(CGFloat)size
    {
        label.numberOfLines = 0;
        NSMutableAttributedString *labelString = [[NSMutableAttributedString alloc] initWithString:label.text];
        [labelString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:size] range:NSMakeRange(0, [labelString length])];
        CGRect labelStringRect = [labelString boundingRectWithSize:CGSizeMake(9999, label.frame.size.height) options:NSStringDrawingUsesLineFragmentOrigin context:nil];
        CGRect labelRect = label.frame;
        labelRect.size.width = labelStringRect.size.width;
        label.frame = labelRect;
        label.attributedText = labelString;
    }
    复制代码
  • 相关阅读:
    跨域资源共享 CORS 详解
    C# 每月第一天和最后一天
    jexus http to https
    ASP.NET MVC 路由学习
    jexus
    centos7 添加开机启动项
    jexus docker
    HTTP2.0新特性
    jexus配置支持Owin
    Autofac Named命名和Key Service服务
  • 原文地址:https://www.cnblogs.com/pb89/p/4829198.html
Copyright © 2011-2022 走看看