我已經使用動態小區大小
CGSize textSize = [text sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:NSLineBreakByWordWrapping];
並返回newHeight
;
來計算表格單元的動態高度。 但在iOS 7中,這不再是。那麼iOS 7也有類似的計算單元格或pickerview行高的動態高度。
更新的代碼:
NSString * text = str.text;
CGSize constraintSize = CGSizeMake(320.0f, 40.0f); // Make changes in width as per your label requirement.
CGRect textRect = [text boundingRectWithSize:constraintSize
options:NSStringDrawingUsesLineFragmentOrigin
attributes:@{NSFontAttributeName:[UIFont fontWithName:@"Avenir" size:17]}
context:nil];
CGSize size = textRect.size;
NSLog(@"textSize :: %f",size.height);
return size.height;
我想設置文本的字體大小,我在下面的方法設置選擇器視圖。
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
NSString *title;
[email protected]"The Grand Bhagvati S G Highway";
return title;
}
可能的重複[在iOS 7中棄用「sizeWithFont:constrainedToSize:lineBreakMode:」我怎麼可以替換?](http:// stackoverflow.com/questions/18903304/deprecated-in-ios-7-sizewithfont-constrainedtosize-linebreakmode-how-can) – Amar