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

    // 设置Label的字体 HelveticaNeue Courier
    UIFont *fnt = [UIFont fontWithName:@"HelveticaNeue" size:12.0f];
    self.subTitleLabel.font = fnt;
    // 根据字体得到NSString的尺寸
    CGSize size = [self.subTitleLabel.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:fnt,NSFontAttributeName, nil]];
    // label的H
    CGFloat textH = size.height;
    // label的W
    CGFloat textW = size.width;
    self.subTitleLabel.frame = CGRectMake(0, 0, textW,textH);

你可能感兴趣的:(ios,标签,字体,label,宽高)