开发者

Why does UITableViewCell backgroundView blur an image

开发者 https://www.devze.com 2022-12-19 16:41 出处:网络
I am subclassing a UITableViewCell and in the init function I am doing the following: UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@\"packagelistcell_background.png

I am subclassing a UITableViewCell and in the init function I am doing the following:

UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"packagelistcell_background.png"]];
[imageView setFrame:CGRectMake(0, 0, 300, 81)];
self.backgroundView = imageView;
[imageView release];

When that displays on the screen, the image appears slightly blurred. For testing, I placed a straight UIImageView above the table view and the image looks perfect and crisp. The table view is a grouped table view. Do you know why it is blurring the i开发者_开发百科mage?


I think the cell has been resized and so is the backgroundView.

Try

imageView.autoresizingMask = UIViewAutoresizingNone;


Try shifting the imageView by 0.5 pixels.


Unfortunately @freytag's solution didn't work for me.

To solve this problem I had to add the UIImageView to a UIView container and set this last as background view of my Custom Cell instead of setting directly the UIImageView:

UIImageView *imgView = [[UIImageView alloc] initWithImage:@"cellBackground.png"];
UIView *backgrContainer  = [[UIView alloc] initWithFrame:self.backgroundView.frame];
[backgrContainer addSubview:imgView];
[self setBackgroundView:backgrContainer];// instead of  [self setBackgroundView:imgView];
[backgrContainer release];
[imgView release];

For some reason setting directly the UIImageView makes it blurry (even if no resize ocurrs). Setting autoresizingMask = None or contentMode <> ScaleToFill for the UIImageView did not fix my problem.

Also beware of the UITableView style, since using a Grouped Style will result in less width for the cell's background view, and this can also resize the image.

( Retina device/simulator doesn't seem to have this problems about blurry image in the cell backgroundVIew)

0

精彩评论

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