下面是我尝试过的代码,但没有帮助,请检查。
static CGFloat cellDefaultHeight = 180;
CGFloat screenDefaultHeight = [UIScreen mainScreen].bounds.size.height;
CGFloat factor = cellDefaultHeight/screenDefaultHeight;
return factor * [UIScreen mainScreen].bounds.size.height;
答案 0 :(得分:1)
在 Swift
中override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat
{
let screenHeight = UIScreen.main.bounds.height
return (cellDefaultHeight/screenDefaultHeight) * screenHeight
}
在目标C
中 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
CGFloat screenDefaultHeight = [UIScreen mainScreen].bounds.size.height;
CGFloat factor = cellDefaultHeight/screenDefaultHeight;
return factor * [UIScreen mainScreen].bounds.size.height;
}
答案 1 :(得分:0)
您应使用heightForRowAtIndexPath
的{{1}}委托方法。
UITableView
答案 2 :(得分:0)
存在逻辑错误 试试这个。
static CGFloat cellDefaultHeight = 180; //lets suppose its a defualt height for iphone6
CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;
CGFloat factor = cellDefaultHeight * (screenHeight / 667) //667 is height of iphone 6
return factor * cellDefaultHeight;