I'd like to have a settings view in my app. I want to have things like UILabels, UISwitches etc. (Like in the Settings app.)
How can I go about doing that? Can I just replace the detailView with the required view, or is there more to it then that? That may not work because I need to be able to set and get text values too.
Take a look at this project.
If you want to do it yourself, you can e.g. attach your own views to the cell's contentView, or use the accessory view to display your switches etc.
You just add your custom views as subviews to the cells content view. Heres an example with an image view:
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 30, 30)];
imageView.image = [UIImage imageNamed:#"SomeImage.png"];
[cell.contentView addSubview:imageView];
Related
I have placed a UIButton inside a static grouped cell and tried to make it fit to the cell border, but get this kind of double-lines:
I tried changing the separator style, but it didn't help. Is there a way to make the border-lines of the button invisible?
Thanks in advance.
From a design perspective, it might be better to add the button as a footer view for the table instead of embedded in a cell. Take a look at Calendar app on the iPhone. When you edit an existing event, they add a button at the bottom of the table for deleting the event. Theirs is a bit fancier than a simple rounded rect button, but that's trivial to do as well.
Embed your login button in a generic UIView and add it as such:
UIView *footerView = [[UIView alloc] initWithFrame:...];
UIButton *logInButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
// do button set up here, including sizing and centering, and add to footer view
[footerView addSubview:logInButton];
self.tableView.tableFooterView = footerView;
[footerView release];
Change button type to custom and it will get rid of the Round Rectangle around the button.
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....
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.
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];
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];