iOS-UILabel的宽度,高度自适应文字

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
    [label setNumberOfLines:0];
    label.text = @"自适应文本你说行不行自适应文本你说行不行自适应文本你说行不行自适应文本你说行不行自适应文本你说行不行";
    label.backgroundColor = [UIColor orangeColor];
    label.font = [UIFont systemFontOfSize:15.0];;

    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
    paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;
    NSDictionary *attributes = @{NSFontAttributeName:label.font, NSParagraphStyleAttributeName:paragraphStyle.copy};

   CGSize labelsize = [label.text boundingRectWithSize:CGSizeMake(320, 999) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil].size;

    [label setFrame:CGRectMake(0, 110, labelsize.width, labelsize.height)];
    [self.view addSubview:label];(http://img.blog.csdn.net/20150327150109525)(http://img.blog.csdn.net/20150327150014161)

你可能感兴趣的:(ios,UILabel,自适应)