zoukankan      html  css  js  c++  java
  • lable自适应宽度和高度

           NSString *nameString = self.dataArray[indexPath.row][@"user"];

            NSDictionary *nameLabelAttr=@{NSFontAttributeName:LLShowMessageNameFont};

           

     //// 自适应宽度

    float rightNameWidth=[nameString sizeWithFont:[UIFont systemFontOfSize:15] constrainedToSize:CGSizeMake(1000, 20)].width;

    //// 自适应高度

            CGSize nameLabelMaxSize=CGSizeMake(rightNameWidth, MAXFLOAT);

            CGSize nameLabelSize=[nameString boundingRectWithSize:nameLabelMaxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:nameLabelAttr context:nil].size;

            

            CGFloat nameLabelX = CGRectGetMaxX(cell.iconView.frame) + LLShowMessageCellBorder*kWidthScale;

            CGFloat nameLabelY = cell.iconView.origin.y;

            cell.nameLabel.frame = (CGRect){{nameLabelX, nameLabelY}, nameLabelSize};

            cell.nameLabel.text = nameString;

    ////如果出现了文字不能全部显示,需要加上一下代码,即可

            [cell.nameLabel sizeToFit];

  • 相关阅读:
    转:孙振耀谈人生(推荐)
    自绘按钮的实现
    数据结构知识
    Direct Show采集图像实例
    视觉跟踪
    改变对话框控件的颜色
    笔试题
    CBitmapButton的使用
    Rotor (SSCLI) 2.0 登场!
    Under the hood: 从Win32 SEH到CLI异常处理模型
  • 原文地址:https://www.cnblogs.com/angongIT/p/4250194.html
Copyright © 2011-2022 走看看