开发者

UITableView background with alpha color causing problem with UITableViewCell

开发者 https://www.devze.com 2023-01-19 13:07 出处:网络
I\'m trying to get a semi-transparent uitableview, with this color [UIColor colorWithRed:(247.0/255.) green:(151.0/255.0) blue:(121.0/255.0) alpha:0.38];

I'm trying to get a semi-transparent uitableview, with this color

[UIColor colorWithRed:(247.0/255.) green:(151.0/255.0) blue:(121.0/255.0) alpha:0.38];

It's ok if there are only empty cells, but when a cell has content inside, the background turns more solid. It's as if the cell itself had the same table background, so that transparency is multiplied.

The cells with content inside are semi-transparent, but with a wrong alpha.

The table background is set correctly

self.myTable.backgroundColor = bgcolor;

The background of the cell is set to clear and not opaque

self.contentView.ba开发者_StackOverflow社区ckgroundColor = [UIColor clearColor];
self.contentView.opaque = NO;

So, why does it has this behavior? Can someone help me?


I solved using a transparent UITableView and putting a semi-transparent UIView behind it.


It's probably caused by the caching of the cell. Have you tried disabling the cache? It's very inefficient ofcourse, but it might help you find a solution for this issue, if it's indeed the UITableViewCell cache is the problem.

You can disable it by not using the "dequeueReusableCell" function in your tableView:cellForRowAtIndexPath: function.


I just met the exact same problem.

After breaking on the -(void)setBackgroundColor on the UITableViewCell class, it seems that it is being called by UITableView internal methods just after the

-(UITableViewCell*)tableView:cellForRowAtIndexPath:

method of your delegate.
Another workaround is to overload the

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath

method in your delegate and set the background color of your cells here.

0

精彩评论

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