label自适应文本大小

UILabel *label = [[UILabelalloc] initWithFrame:CGRectZero];

    NSString *string = @"aa2fkoksdajfisd32323koiwejfskmfiweja2332e23ksdvjekosdko是是是是是是";

    CGSize consSize = CGSizeMake(320, 2000);

    CGSize size = [string sizeWithFont:[UIFontsystemFontOfSize:16] constrainedToSize:consSize];

    label.numberOfLines = 0;

    label.font = [UIFont systemFontOfSize:16];

    label.text = string;

    label.backgroundColor = [UIColorredColor];

    label.frame = CGRectMake(0, 0, size.width, size.height);

    [self.view addSubview:label];

原文地址:https://www.cnblogs.com/chenhaosuibi/p/3482887.html