开发者

UIImageView in UITableCell gets a weird size

I开发者_StackOverflow'm trying to place a UIImageView in a UITableViewCell.

I create a special view called ProductView. In that view, I have several components, one of them being a UIImageView. I set this ProductView as content view of the UITableViewCell. Everything is drawn properly except the UIImageView. UIImageView gets scaled meaninglessly. It's height gets twice the height of the table cell size.

I've spent hours trying to solve this problem. I've set the frame of UIImageView manually, I've called drawRect method of UIImage in UIImageView, neither of them worked.

I'm thinking of replacing UITableView with a UIScrollView if I can't find a solution. Does anyone know how to solve this problem?


Use the Custom cells, and place all the UI component inside that cell, (including the UIImageView), and in cellForRowAtIndexPath method, set the image like following:

[cell.imgView setContentMode:UIViewContentModeScaleAspectFit];
[cell.imgView setFrame:CGRectMake(cell.imgView.frame.origin.x, cell.imgView.frame.origin.y, 120, 79)];      
[cell.imgView setImage:[UIImage imageNamed:@"image.png"]];          

And if you need to know how to use custom cells, follow this tutorial :

iPhone Programming Tutorial: Part 6: Creating custom UITableViewCell Using Interface Builder [UITableView]

Hope this helps you...


I've had the same problem and realized in the end that the issue wasn't anything to do with automatic resizing, it was simply that I was not getting the UIImageView, but its parent view (the table cell), due to clashing tag values (I was getting the view through callUIImageView *pictureView = (UIImageView *)[cell viewWithTag:0]; and tag zero was also set on the cell). Fixed by just changing the tag value.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜