Centering UITableViewCell subviews when row heights vary in a UITableView
I am using a slightly larger backgroundView image for the last row of my table. When the last cell is displayed, the imageView, textLabel, and accessoryView are all maintaining the same margin from the bottom of the cell, rather than maintaining their position in the center of the cell like they do on the other rows of smaller height. This gives the appearance of everything being 开发者_JS百科very low in the larger cell.
I am looking for away to keep these subviews in a standard UITableViewCellStyleDefault centered with the cell despite it's height.
Currently, I'm setting the row height using this delegate:
- (CGFloat)tableView:(UITableView *)tableView
heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 1 && (indexPath.row + 1) == [myList count]) {
return 65.0;
}
else {
return 50.0;
}
}
The best way is probably to subclass UITableViewCell
and to overwrite the layoutSubviews
method.
精彩评论