开发者

How to make semi-transparent UITableViewCells?

I hope to add image to cell background and from the semi transparent cell I could see the backgroud of tableview.

From following topic, I know how to make transparent cell.

UITableViewCell transparent background (including imageView/accessoryVie开发者_开发问答w)

I've tried above, it did work. But when I add the following code:

UIView *backView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
backView.backgroundColor = [UIColor colorWithRed:.1 green:.1 blue:.1 alpha: .4];
cell.backgroundView = backView;

The cell became grey color without any transparency, if I change code as follows,

UIView *backView = [[UIView alloc] initWithFrame:CGRectZero];
backView.backgroundColor = [UIColor clearColor];
cell.backgroundView = backView;

The cell became white, still without any transparency.

Is there one can give me any clues?


To make your UITableViewCells Semi-Transparent that is Translucent, you have to make your UITableViewCells Transparent and then, set cell's backgroundView to an image which has translucent properties. Also set selectedBackgroundView of the cell to an image which is translucent and gives a selected cell's effect.

UIView *backView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
backView.backgroundColor = [UIColor clearColor];
cell.text.backroundColor = [UIColor clearColor]; //if you have labels on cells..
cell.backgroundView = backView;

Then set an image with translucent effect on our transparent cell..

UIImageView *cellImage = [[UIImageView alloc] init];
[cellImage setImage:[UIImage imageNamed: @"unselectedCellImage.png"]];
[cell setBackgroundView:cellImage];
[cellImage release];

Then set an image for selected cell to give an translucent effect after selection also..

UIImageView *cellImageSelection = [[UIImageView alloc] init];
[cellImageSelection setImage:[UIImage imageNamed: @"selectedCellImage.png"]];
[cell setSelectedBackgroundView:cellImageSelection];
[cellImageSelection release];

It'll work.. Cheers..


You can try this one

UIView *backView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
backView.backgroundColor = [UIColor colorWithRed:255 green:255 blue:255 alpha: .2];
cell.backgroundView = backView;

What you did wrong was you choose .1 .1 .1 which is for black color you need 255 255 255 for the white color and your opacity was very high so it looked gray color to you actually it was black with opacity. Hope this helps :)


Views are initialized as opaque by default, so you probably need to explicitly set backView.opaque = NO; in order for it to draw with any transparency.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜