根据text获取当前label的总行数

 UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 100, SCREENWIDTH, 100)];

    label.textColor = [UIColor blackColor];

    label.text = @"俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋俊洋洋";

    label.font = [UIFont systemFontOfSize:16];

    label.numberOfLines = 0;

    [self.view addSubview:label];

    [label sizeToFit];



    CGRect rect = [label.text boundingRectWithSize:CGSizeMake(SCREENWIDTH, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16]} context:nil];

    CGSize textSize = [label.text sizeWithAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:16]}];

    NSUInteger textRow = (NSUInteger)(rect.size.height / textSize.height);

    NSLog(@"fdafafa--%d",textRow);//行数


你可能感兴趣的:(移动开发)