UILabel自适应高度和自动换行

 // 初始化label

    UILabel *label = [[UILabel alloc] init]; 

    NSString *text = @"这是一个测试!!!adsfsaf时发生发勿忘我勿忘我勿忘我勿忘我勿忘我阿阿阿阿阿阿阿阿阿阿阿阿阿啊00000000阿什顿。。。"

    label.text = text;

    [label setNumberOfLines:0];  

    UIFont *font = [UIFont fontWithName:@"Arial" size:14];

    //设置字体

    label.font = font;

    CGSize constraint = CGSizeMake(300, 20000.0f);

    CGSize size = [text sizeWithFont:font constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];

    [label setFrame:CGRectMake(10, 0, size.width, size.height)];

    [self.view addSubview:label];


你可能感兴趣的:(测试)