0

以下是我尝试过的代码,但没有帮助,请检查。

static CGFloat cellDefaultHeight = 180;
CGFloat screenDefaultHeight = [UIScreen mainScreen].bounds.size.height;
CGFloat factor = cellDefaultHeight/screenDefaultHeight;
return factor * [UIScreen mainScreen].bounds.size.height;
4

3 回答 3

1

斯威夫特

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;
    }
于 2018-08-08T07:38:20.083 回答
0

你应该使用heightForRowAtIndexPath委托方法UITableView

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return [UIScreen mainScreen].bounds.size.width;
}
于 2018-08-08T07:31:45.400 回答
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;
于 2018-08-08T07:37:37.887 回答