【发布时间】:2015-12-19 01:31:22
【问题描述】:
我在 .xib 中制作了一个简单的表格视图。我想为所有屏幕尺寸(即 iphone 6、6 plus 和 ipad)扩展表格视图单元格。目前我已经硬编码了不同屏幕的不同高度,如下所示:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath: (NSIndexPath *)indexPath{
CGFloat cellHeight = 0;
if (IS_IPHONE_6P) {
// iphone 6P
// cellHeight = 133;
cellHeight = 175;
}
else if (IS_IPHONE_6){
// on iphone 6
// cellHeight = 120;
cellHeight = 160;
}
else if (IS_IPHONE_5){
//On iphone 5
// cellHeight = 105;
cellHeight = 145;
}
else if (IS_IPHONE_4_OR_LESS){
// on iphone 4
// cellHeight = 50;
cellHeight = 130;
}
else {
//on ipad
// cellHeight = 200;
cellHeight = 280;
}
// cellHeight = cellHeight *2;
return cellHeight;
}
我有更好的方法吗?
【问题讨论】:
-
CGRectGetHeight([UIScreen mainScreen].bounds) * 比例
标签: ios objective-c swift uitableview ios8