Reputation: 85
Below is the code I had tried but it's not helpful please check.
static CGFloat cellDefaultHeight = 180;
CGFloat screenDefaultHeight = [UIScreen mainScreen].bounds.size.height;
CGFloat factor = cellDefaultHeight/screenDefaultHeight;
return factor * [UIScreen mainScreen].bounds.size.height;
Upvotes: 0
Views: 141
Reputation: 3613
You should use heightForRowAtIndexPath
delegate method of UITableView
.
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return [UIScreen mainScreen].bounds.size.width;
}
Upvotes: 0
Reputation: 7669
In Swift
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat
{
let screenHeight = UIScreen.main.bounds.height
return (cellDefaultHeight/screenDefaultHeight) * screenHeight
}
In Objective 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;
}
Upvotes: 1
Reputation: 1616
its a logical error Try this.
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;
Upvotes: 0