美文网首页
iOS 动态确定Label宽高

iOS 动态确定Label宽高

作者: 夏天爱西瓜汁 | 来源:发表于2017-11-28 11:23 被阅读10次

    2016.4.30

    // iOS7_API_根据文字 字数动态确定Label宽高

    // 设置Label的字体 HelveticaNeue  Courier

    UIFont *fnt = [UIFont fontWithName:@"HelveticaNeue" size:24.0f];

    _nameLabel.font = fnt;

    // 根据字体得到NSString的尺寸

    CGSize size = [_nameLabel.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:fnt,NSFontAttributeName, nil]];

    // 名字的H

    CGFloat nameH = size.height;

    // 名字的W

    CGFloat nameW = size.width;

    _nameLabel.frame = CGRectMake(0, 0, nameW,nameH);

    相关文章

      网友评论

          本文标题:iOS 动态确定Label宽高

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