开发者

Transparent background in grouped UITableView - iPhone

开发者 https://www.devze.com 2022-12-22 16:52 出处:网络
I want to make the grouped UITableView transparent. I partially succeded with the following 开发者_JAVA百科code:

I want to make the grouped UITableView transparent. I partially succeded with the following 开发者_JAVA百科code:

UIColor *bgColor = [[UIColor alloc] initWithWhite:1 alpha:0.0];
historyTable.backgroundColor = bgColor;

Unfortunately, black corners appeared in the rounded cells. How to get rid of them?

Transparent background in grouped UITableView - iPhone

Transparent background in grouped UITableView - iPhone


Instead of using

UIColor *bgColor = [[UIColor alloc] initWithWhite:1 alpha:0.0];
historyTable.backgroundColor = bgColor;

Just use:

historyTable.backgroundColor = [UIColor clearColor];

That also clears up the memory leak you were creating.


remove UITableView backgroundView

xxx.backgroundView = nil;

This is necessary on iPad builds. When compiling to run on iPad and iPhone, check the tableView responds to the selector with ...

if ([self.tableView respondsToSelector:@selector(setBackgroundView:)]) {
    [self.tableView setBackgroundView:nil];
}


for me it worked finaly after setting both to nil/clear:

[myTableView setBackgroundView:nil];
[myTableView setBackgroundColor:[UIColor clearColor]];


I had this issue and found that there was no difference between using:

[[UIColor alloc] initWithWhite:1 alpha:0.0];

and using:

[UIColor clearColor];

I tried both of these and still had the little black corners on my table view.

I also tried setting the backgroundView to nil as suggested, but this didn't work either.

I solved this by setting the backgrounds of the individual cells to transparent in the cellForRowAtIndexPath method:

cell.backgroundColor =  [UIColor clearColor];

Of course, this has the side effect that your cells themselves are transparent, which isn't ideal for everyone, but it ok for me in this case.

0

精彩评论

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

关注公众号