计算有label有多少行

2018-01-23  本文已影响0人  frola_
    CGRect rect = [wellKnowSayingLabel.text boundingRectWithSize:CGSizeMake(SCREENWIDTH-50, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:20]} context:nil];
    
    CGSize textSize = [wellKnowSayingLabel.text sizeWithAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:20]}];
    
    NSUInteger textRow = (NSUInteger)(rect.size.height / textSize.height);
    
    NSLog(@"label有%@行",textRow);//行数
上一篇 下一篇

猜你喜欢

热点阅读