UILabel自适应高度和自动换行

//初始化label



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



    NSString *text = @"阿萨德j啊思考的卡洛斯抵抗力将萨克林顿将拉开始监督卡拉基斯克林顿j啊思考了监督卡时间考虑到j啊思考了登记卡收录机抵抗力。。。"; 



    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];

 

你可能感兴趣的:(UILabel)