Set background of UITableview in interface builder? - iphone

In iPhone I need to set the background view of a UITableview. From 3.2 SDK I can in code use something like:
[self.tableView setBackgroundView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"mycustombackground.png"]]];
But how can I do the same in interface builder? It would be great if I could just set the background view directly in interface builder. But can't seem to find this property, where is it?
Thanks!

Add a UIImageView behind it, put the image in that and set the tableview to transparent:
self.tableview.backgroundColor = [UIColor clearColor];

Related

How to set accessory view background to same background as content view in UItableViewCell?

I've successfully changed the background of table view cells to an image in my app but it does not extend to the background of the accessory view. Any idea to fix this ?
Thx for helping,
Stephane
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"bg-Cell-Image.jpg"]];
try this way if you are using text label of the cell only to display content
You can use the tableView:willDisplayCell:forRowAtIndexPath: delegate function of tableview. Give background color to the cell in that function. It will give the color to accessary view background also.
This is an old thread, that I found most helpful. What worked for me though, was to set the cell color in IB (the cell was a prototype):

background image confusion using UINavController

I am having trouble explaining this to myself but here is my best attempt.
I have a rootViewController that has a unique background imageView (placed in IB). When the user advances from that screen a navigationController is loaded in with a standard background color and can advance through the next screens. Is it possible to have just one image always stay as the background, i know i can use:
self.tableView.backgroundColor = [UIColor clearColor];
to allow the background to show through, but for some reason when i do this i see the first background image(the unique one), not the one that i have added to the Navigation controller.
This is the code that i use to add a bg to the nav controller:
UIImage *img = [UIImage imageNamed:#"v3_default_bg.png"];
UIImageView *bgView = [[UIImageView alloc] initWithFrame:self.view.frame];
bgView.image = img;
[appDelegate.navigationController.view sendSubviewToBack:bgView];
My question is this, is it possible to apply a non-unique background to the navigationController.
I also tried addSubview: instead of sendSubviewToBack: but that just blocks out my content. Could anyone lend me some thoughts? Thanks.
[appDelegate.navigationController.view sendSubviewToBack:bgView];
does not add the subview to the navigationController.view. You need to add it, then send it to the back:
[appDelegate.navigationController.view addSubview:bgView];
[appDelegate.navigationController.view sendSubviewToBack:bgView];
hide the navigation bar and then put Ur view there....

Setting a jpg as the background for a UIView?

I know this is a very beginner question, but I'm obviously a beginner. I have already made a my TabBar but I want to set the background of one of the views as a (jpg) I created. I need to add the background in code (not IB) so that I can allow rotation and resizing when the iphone is rotated.
-thanks
You need to use a UIImageView, which is a subclass of UIView. You can create it as follows:
UIImageView *myImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"myImage.jpg"]];
[self.view addSubview:myImage];
[myImage release];
...so here I've created a UIImageView that uses a JPG called 'myImage' (it will automatically resize the view to fit the image), added it to my view controller, and then cleaned up my memory.
You can try this one to set an image as a background for a view programmatically:
view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"imageName.png"]]
Add an instance of UIImageView to your view, and set it's image to an instance of UIImage created using your file.
You can add the image view in IB or in code -- there's nothing about doing it in IB that would prevent you from resizing, rotating, etc.

How to use the default background image for iPhone UIView?

How can I use the default background image for a UIView?
theView.backgroundColor = [UIColor groupTableViewBackgroundColor];
You can do something like this with UIView class:
[yourview setBackgroundColor:
[[UIColor alloc]
initWithPatternImage:[UIImage imageNamed:#"yourpattern.png"]]];
I always prefer using Interface Builder and just put a UIImageView occupying all UIView and send that UIImageView to back though...
if you are using Interface Builder you can choose "Group Table View Background Color" in the inspector of your UIview.
i just found out this when I read the above answer to your problem (i was trying to do that exatly :P)

How to set background color for View and not for the Table?

I have downloaded TableView sample code '4_TableViewCellSubviews' from internet. I am trying to run this program in my way. I am trying to set my own background view color as 'lightgraycolor'. I just wanted to see the background view as lightgraycolor in this application. I don't want to make any color for TableView. i.e I want to give gray color only for the background view, not for the background of table.
When I provide the code for that as '[self.view setBackgroundColor:[UIColor lightGrayColor]];' , it is changing the color for the entire table as well.
But I am trying to set Color only for the view which besides on the Table. How to set background color only for the background view and not for the TableView. I know that the code which I provide to set the color background view is perfect. What are the possibilities that we would get to occur with this issue and solution for this?
I have kept the screenshot at the following location:
http://www.quickfiles.net/894107
Update
I think most you all have misunderstood my problem. I want to have color on the space when we scroll DOWN the Table we see a empty space on the top in the background of tableview.
For example, download a free news application called, "BusinessWeek". You can launch this app in your iPhone device. You can see the home screen and scroll DOWN the table there. You can see the background color as Gray color of the Table. I want to do the same way, what should I do for that?
In this case here, the 'view' and 'tableView' are the same actually, that's the color change doesn't work as you want it to. To convince you of that, add these 2 lines in the 'viewDidLoad' function, and look at what is output in the console when you run your program:
NSLog(#"tableView: %#", self.tableView);
NSLog(#"view: %#", self.view);
Sorry, the earlier answer comment needs to modified as below steps. I am writing the solution here because some one else if they come across they can use it.
In I.B, Create UIView and set the color whatever you want. Create Table on top of it.
Create a TableView variable in your code and connect that with I.B Table.
In viewDidLoad, add like below.
myTableView.backgroundColor = [UIColor clearColor];
myTableView.alpha = 0.9;
[super viewDidLoad];
Add the below code in cellForRowAtIndexPath:
UIView *v = [[UIView alloc] initWithFrame:cell.frame];
v.backgroundColor = [UIColor whiteColor];
cell.backgroundView = v;
[v release];
// If you want accessory type add this below line ..
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
Build and Run you application.
[tableView setBackgroundColor:[UIColor clearColor]];
You should add the tableView as a subview of the MainView. Create a ViewController class and programmatically add the tableview methods and delegate. At program start, add your tableview as a subView of the Mainview. In this way UITableView and UIView should be two distinct parts, and you should be able to change the background color properly.
My problem was also same whatever the below existing query is talking about 'Gutter' color change:
Set UITableViewCell background color on plain style table view?
Currently i have resolved it by the following code:
I have created a UIView and set the background color as 'Gray'. I created a TableView on top of it and connect with the tableView variable there.
When i run my app, it has shown the Gray color in the background view and also in Table. I don't want that color in Table, so added the below code as well to remove it.
in 'viewDidLoad'
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
UIView *myView = [[UIView alloc] initWithFrame:cell.frame];
myView.backgroundColor = [UIColor whiteColor];
cell.backgroundView = myView;
[myView release];
cell.contentView.backgroundColor = [UIColor whiteColor];