Reputation: 2181
I want to add UITableViewCells Height constraint equal to another View which is named as the Header View
In My SuperView I have a HeaderView on top. I have set its height constraint as 1/10 to my superView.
I have a UITableView in which there is a UITableViewCell. 1. Set the height constraint of the UITableViewCell in a ratio of 1/10 to the superview. or 2. Set the height constraint equal to HeaderView.
Can i add a constraint on the Interface Builder from my UITableViewCell to the Header View or the superview?
Upvotes: 0
Views: 544
Reputation:
You can't set constraints to height for either table cell or table header from storyboard. You can use following functions to make the height 1/10 of superview for both header and table cell:
// For table header view
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
CGFloat height = <superview>.frame.size.height/10;
return height;
}
// For table cell
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
CGFloat height = <superview>.frame.size.height/10;
return height;
}
Upvotes: 1
Reputation: 2050
You can set the row height to be 1/10 of the screen height like this
tableView.rowHeight = UIScreen.mainScreen().bounds.height/10
Let me know if this is working
Upvotes: 1