开发者

How can I stop my custom UITableViewCell backgroundImage from being stretchable?

If I create a background image for my table cell in the init method of my UITableViewCell subclass, the image comes out exactly how I drew it, and tableView:heightForRowAtIndexPath: simply adds a gap around it.

But if instead I create the background image in my tableView's tableView:cellForRowAtIndexPath: method and set it, changing the cell height will now stretch the image.

I need to create t开发者_StackOverflow社区he background views in the cellForRowAtIndexPath method, as the background changes for different rows. How can I make my image's size fixed again?


Have you tried setting the contentMode to UIViewContentModeCenter for the backgroundView of the cell?

put it here

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
     cell.backgroundView.contentMode = UIViewContentModeCenter;
}


You could create something with:

UIView *cellBackView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
<insert image>;
cell.backgroundView = cellBackView;

My guess is the backgroundView gets strechted automatically, but you could make sure the image isn't stretched on that view by setting a width and height. This way, you can do whatever you like with that view.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜