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];
Related
I have a standard UITableView with three sections. At the bottom of the table I'm trying to add a tableFooterView. It seems as though there's a standard spacing between the last row in the table and the top of the tableFooterView, which is fine, but my problem is that there is a different color in this spacing that I can't get rid of. I need that spacing to match the background of my tableView.
Here's some code:
self.menuTable.backgroundColor = [UIColor redColor];
self.menuTable.backgroundView = nil;
self.menuTable.separatorColor = [UIColor clearColor];
self.menuTable.delegate = self;
self.menuTable.sectionHeaderHeight = 10.0;
UIView *footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 200)];
footer.backgroundColor = self.menuTable.backgroundColor;
UILabel *footerLabel = [[UILabel alloc] initWithFrame:CGRectMake(60, 0, 205, 100)];
footerLabel.text = #"foo bar.";
footerLabel.textColor = [UIColor blackColor];
footerLabel.backgroundColor = self.menuTable.backgroundColor;
footerLabel.numberOfLines = 10;
footerLabel.font = [UIFont italicSystemFontOfSize:11.0];
[footerLabel sizeToFit];
[footer addSubview:footerLabel];
self.menuTable.tableFooterView = footer;
Here's a screenshot (sorry about the red, but it's the easiest way to see the differences in colors).
Whoops. Earlier I was trying to add a sectionFooterView, and had implemented tableView:heightForFooterInSection:, returning 20 for the last section. That's where that gap was coming from, and it had a default color of white. Since I'm now placing the text as the tableFooterView, I just removed that delegate callback and everything is rendering as expected.
Try this
self.menuTable.backgroundColor = [UIColor clearColor];
self.view.backgroundColor = [UIColor redColor];
I have 10 UIButtons that I want to change the background color of.
Here's what I have right now:
b1.backgroundColor = [UIColor redColor];
b2.backgroundColor = [UIColor redColor];
b3.backgroundColor = [UIColor redColor];
b4.backgroundColor = [UIColor redColor];
b5.backgroundColor = [UIColor redColor];
b6.backgroundColor = [UIColor redColor];
b7.backgroundColor = [UIColor redColor];
b8.backgroundColor = [UIColor redColor];
b9.backgroundColor = [UIColor redColor];
b10.backgroundColor = [UIColor redColor];
I wonder if there is another, simpler, way of doing this. I have all ready tried UIButton.backgroundColor = [UIColor redColor] but that didn't work.
//Make an array of the buttons:
NSArray* buttons=[[NSArray alloc] initWithObjects:b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,nil];
//Loop through them
for(UIButton* b in buttons)
{
b.backgroundColor = [UIColor redColor];
}
The array could also be initialized in viewDidLoad.
Put the buttons in an array:
NSArray* buttonArray=[[NSArray alloc] initWithObjects:b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,nil];
Then set the background color for all the buttons:
[buttonArray makeObjectsPerformSelector:#selector(setBackgroundColor:) withObject:[UIColor redColor]];
Create an array of your buttons in viewDidLoad. Then just use a for loop to change colors.
I want my UITableView to be completely invisible but I have set a lot of things and nothing seems to be working.
I use custom table cells.
This is what I set in the cell.h
self.textLabel.backgroundColor = [UIColor clearColor];
primaryLabel.backgroundColor = [UIColor clearColor];
secondaryLabel.backgroundColor = [UIColor clearColor];
self.backgroundColor = [UIColor clearColor];
self.contentView.backgroundColor = [UIColor clearColor];
self.backgroundView.backgroundColor = [UIColor clearColor];
self.accessoryView.backgroundColor = [UIColor clearColor];
self.selectedBackgroundView.backgroundColor = [UIColor clearColor];
And I also set
_tableView.backgroundColor = [UIColor clearColor];
But still it is not working, what am I missing?
Instead, you could use the hidden property of the tableView.
tableView.hidden = YES;
With regards to the "incorrect" answer given, I think you mean is that you want the tableView background to disapear (showing the views background).
If so, in your viewDidLoad, add the following: (given you made your tableView programmatically)
[self.tableView setBackgroundColor:[UIColor clearColor]];
If you also don't want to show the lines for each cell:
[self.tableView setSeparatorColor:[UIColor clearColor]];
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;
I've added custom background image to my UITableView and it shows fine. Than, i removed any background color from the cells. Now i expect to see only cells' text on top of table's background image, however i see strange behaviour. Cells take pattern color of table's background image, so that i see waves like in the picture:
The background image shell look like this:
*pay attention to white circles that disappear under the cells!
My code is as follws:
in viewDidLoad i set the background image of table view:
self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"general_bg.png"]];
For each cell i remove any background color like this:
UIView *bckView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
bckView.backgroundColor = [UIColor clearColor];
cell.backgroundView = bckView;
cell.backgoundColor = [UIColor clearColor];
cell.contentView.backgroundColor = [UIColor clearColor];
UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectMake(x,y,x1,y1)];
textLabel.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview:textLabel];
line separators are custom images added to cells.
Instead of setting the BackgroundColor attribute of the tableview, try setting the backgroundview:
UIView *background = [[UIView alloc] initWithFrame:self.tableView.bounds];
background.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"YOUR_IMAGE.png"]];
self.tableView.backgroundView = background;
This should fix the issue of the cell's taking on the same image as the background.
self.tableView.backgroundView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"YOUR_IMAGE.png"]];
maybe this is what you're looking for