美文网首页
iOS UILabel自定义宽高

iOS UILabel自定义宽高

作者: T_label | 来源:发表于2016-08-01 11:52 被阅读33次
    • 自定义高度
      -(CGFloat)getHeightByWidth:(CGFloat)width title:(NSString *)title font:(UIFont *)font{
      UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, width, 0)];
      label.text = title;
      label.font = font;
      label.numberOfLines = 0;
      [label sizeToFit];
      CGFloat height = label.frame.size.height;
      return height;
      }

    • 自定义宽度
      -(CGFloat)getWidthWithTitle:(NSString *)title font:(UIFont *)font {
      UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 1000, 0)];
      label.text = title;
      label.font = font;
      [label sizeToFit];
      return label.frame.size.width;
      }

    相关文章

      网友评论

          本文标题:iOS UILabel自定义宽高

          本文链接:https://www.haomeiwen.com/subject/udvxsttx.html