sizeThatFits

UILabel * lagrl = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 0, 100 )];
lagrl.backgroundColor = [UIColor redColor];
lagrl.text = nil;
[self.view addSubview:lagrl];
lagrl.hidden = true;
NSLog(@"%@",NSStringFromCGPoint(lagrl.center));

CGSize suggestSize = [lagrl sizeThatFits:CGSizeMake(200, 30)];

NSLog(@"%@",NSStringFromCGSize(suggestSize));

如果label放入text为nil,那么获得到的suggestSize将会是 {0, 0};

你可能感兴趣的:(sizeThatFits)