Search This Blog

Thursday, February 23, 2012

UITableViewCell and Centering an Image

This is one of those code snippets that took me a while to find on the net so I thought I would put it here so maybe someone else might come across it without too much difficulty.  Its just one of those weird iOS development problems.

How to center a UIImageView within a custom cell?

    UIImageView *pic = [[UIImageView alloc] initWithImage:[arr objectAtIndex:indexPath.row]]; = CGPointMake(cell.contentView.bounds.size.width / 2 , 60);
    pic.contentMode = UIViewContentModeScaleAspectFit;
    cell.selectionStyle = UITableViewCellSelectionStyleGray;
    [cell.contentView addSubview:pic];

 [arr objectAtIndex:indexPath.row]] is just an array holding my images.  It could be any image here.

No comments:

Post a Comment