开发者

Centering UITableViewCell subviews when row heights vary in a UITableView

开发者 https://www.devze.com 2022-12-21 03:12 出处:网络
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 th

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号