How to set table background transparent in iphone? - iphone

I am new to iphone development .I have displayed a list of contents in a grouped table view.How can set the table background transparent such as i should see the text displayed on the gray-color(default color) background and not on the white color.Please help me out.Thanks.

cell.backgroundColor=[UIColor clearColor]
This worked fine for me.

table.backgroundColor = [UIColor clearColor]
Marco

cell.backgroundColor = [UIColor clearColor];
cell.backgroundView = nil;
table.backgroundView = nil;
This works for me.

In iOS 6 seems this is not enough. I have to set both,
menuTable.backgroundColor = [UIColor clearColor];
if ([menuTable respondsToSelector:#selector(setBackgroundView:)]) { // only after 3.2
[menuTable setBackgroundView:nil];
}

self.view.layer.backgroundColor = [UIColor clearColor].CGColor;
Works on iOS 9.

UITableView inherits a 'alpha' property from UIView so try changing that :)

Related

How to make a UITableView as transparent one?

In my application, i am presenting an UITableViewController class (Grouped style) to the user for the particular scenario. I want to show the table view's cells only. The background should be transparent so that the user can see the previous page.
I tried with the following codes in viewDidLoad method of the table view controller. But they are not working..
self.tableView.backgroundColor = [UIColor clearColor];
self.tableView.opaque = NO;
self.tableView.backgroundView = nil;
Is it possible to show the cells with a dimmed background?
Thanks in Advance
I use: (in viewDidLoad)
self.tableView.backgroundColor = [UIColor clearColor];
self.tableView.opaque = NO;
Then in cellForRowAtIndexPath:
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.detailTextLabel.backgroundColor = [UIColor clearColor];
cell.backgroundColor = [UIColor colorWithWhite:1 alpha:.55];
Not sure if this is what you wanted, but it gives you the option to make everything clear. (obviously the alpha would change for your case, but that measures theo pacity of the cells)
Just altering the tableView doesn't help. You have to mess with the cells also. Inside the cellForRowAtIndexPath:(NSIndexPath *)indexPath method, put this before the return statement:
UIView * bgView =[[UIView alloc] initWithFrame:CGRectZero] autorelease];
bgView.backgroundColor = [UIColor clearColor];
cell.backgroundView = bgView;

UITableViewCell with background image does not look good

I created my UITableViewCellStyleDefault styled cell and set its background image:
cell.backgroundView = imgView;
and it works but the background of the text in the cell is still white.So it hides partially the backgroundView.
I have tried:
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.contentView.backgroundColor = [UIColor clearColor];
cell.textLabel.opaque = NO;
but none of them worked.
Also the image used for backgroundView has transparent parts but in the cell the are not.
I wonder what I am missing.
Thanks in advance.
Refer to this: Changing UITableViewCell textLabel background color to clear

Problems setting background for grouped UITableView

I want to have a background image behind my UITableView. This works fine, but for each grouped UITableView it seems to be using my background image. I just want it to use the background image once:
Note: This is all inside of a UITableViewController class
self.view.backgroundColor = [[[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"background.png"]]autorelease];
self.tableView.opaque = NO;
self.tableView.backgroundView = nil;
headerView.backgroundColor = [UIColor clearColor];
footerView.backgroundColor = [UIColor clearColor];
You need to do two things:
Set background view (color) not in the UITableViewController, but in his parent (UINavigationController most likely, right?)
self.parentViewController.view.backgroundColor = [UIColor redColor]; // or whatever your image is
Set clear color for tableView background color (and optionally for its separatorColor)
self.tableView.separatorColor = [UIColor clearColor];
self.tableView.backgroundColor = [UIColor clearColor];

Transparent background in grouped UITableView - iPhone

I want to make the grouped UITableView transparent. I partially succeded with the following 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?
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.

iPhone Fixed-Position UITableView Background

I'm building an iPhone app without the use of Interface Builder. I have set the background of a grouped UITableView in the following manor:
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"groupedBackground.png"]];
I'm trying to fix this background image so that it doesn't scroll with the table cells. Does anyone know how to do this?
We find that it works exactly as you ask, if instead of using backgroundColor, you assign to backgroundView, like so:
self.tableView.backgroundView = [[UIImageView alloc] initWithImage:
[UIImage imageNamed:#"background.png"]];
The table cells then scroll on top of the background, which is stationary. (This has been available since version 3.2 of the SDK, I believe.)
You can achieve a stationary background using a pattern image as follows:
UIView *patternView = [[UIView alloc] initWithFrame:tableView.frame];
patternView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"groupedBackground.png"]];
patternView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
tableView.backgroundView = patternView;
A little late but maybe for all the others looking for a solution. I could get that work by calling the parentViewController in the viewDidLoad method of the UITableViewController:
self.parentViewController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"background.png"]];
self.tableView.backgroundColor = [UIColor clearColor];
or with using just a background color:
self.parentViewController.view.backgroundColor = [UIColor scrollViewTexturedBackgroundColor];
self.tableView.backgroundColor = [UIColor clearColor];
It took me a while to figure that out but now it works like a charm.
You can place an additional view below UITableView and set its background, so if UITableView is transparent - you'll achieve your goal - it will have correct background and it will not scroll.
use this below code in swift 3.0 to achieve constant background for tableview
self.tableView.backgroundView = UIImageView(image: UIImage(named: "background.png")!)