How to change UITableView's appearance? - iphone

What different kinds of things can you do to edit a tableview's appearance and how would you do them? For example, how would you change the color programmatically? Or change the navigation bar's color programmatically?

Check out the docs for UITableView and UITableViewCell.
You probaby want to change the backgroundColor property or customize each cells contentView property. Also,look into layers, you can do things like make rounded corners, shadows, etc on a views layer.
Here is the QuartzCore Framework docs. They should be useful if your trying to change the appearance of a view.
Edit (good suggestion bshirley):
AboutTableViewsiPhone

Check out Apple's doc on UITableView particularly the configuring A Table View section.

[tableView setBackgroundColor:[UIColor grayColor]];
or You can use,
[tableView setBackgroundColor:[colorWithRed:.98 green:.98 blue:.82 alpha:1]];

If you want to change the appearance of all TableViews in your app you can define it with the Appearance property. In Monotouch you do something like this:
UITableView.Appearance.BackgroundColor = UIColor.Black;
UITableViewCell.Appearance.BackgroundColor = UIColor.Black;
In objective C it would be something similar.

Related

Change the color in between cells in grouped table view

I need to know how to change the color in between the cells in Grouped UITableView
Note: the UITableView have a Background color of some other color
So, How to implement the following:
I do believe the correct way to do this is setBackgroundColor for the tableview. you can do this in the viewDidLoad method so the color is already set when the view loads
Edit:
I would suggest make a custom subclass of UITableViewCell with the background color/image already included in the cell. Then you would have to also set the headers and footers to have the same background color/image. I believe this would be the easiest way to accomplish what you want

UITableViewCell contentLayer backgroundColor won't cover accessory's background

I'm writing a small application to teach myself new design and information retrieval tricks. I'm using the following line to set the background of my UITableViewCell subclass:
cell.contentView.backgroundColor = [UIColor blackColor];
... but it doesn't seem to want to get behind that accessory view:
How do I get the backgroundColor to actually span the entire background of the UITableViewCell?
The accessory view is not added to the cell's contentView. As you can see, the content view is resized by shrinking from the right so the accessory can fit in. This also happens when the delete button is shown.
You need to set the backgroundColor of the whole cell - furthermore, this has to be done in the tableView:willDisplayCell:forRowAtIndexPath:
delegate method.
If you want to set color of entire cell, then use -
cell.backgroundColor = [UIColor blackColor];
Not exactly a definitive answer to this question, but it works well when you use the "grouped" view instead of the standard UITableView style.

How can I group editable information like in Apple's "Settings" application?

I'm looking to make a view similar to Apple's "Settings" application.
Example: http://www.amitbhawani.com/apple/Images/I/iphone-MMS-Settings.jpg
How can I set up my application to look/work like that?
You'll need to use a UITableView with the style set to UITableViewStyleGrouped for the appearance. For editable fields you should be able to add UITextField views to the contentView property of the tableView cells.
That's just a grouped tableview, with section headers.
Like others have said, you want to make use a UITableView with grouped styles. In your
- (void) viewDidLoad
method, add the following line of code:
[self.tableView initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.framw.size.height) style: UITableViewStyleGrouped];
It should give you the appropriate style.
I would say that you should add switches and text fields as accessoryViews, not contentViews, though.
See the Documentation for more on customizing UITableView.
Also, see my question here, the answers there may be helpful: Custom UITableViewCell for Settings-like application?

Adding a subview to UITableCellView

I want to add a subview to the UITableCellView class. However, non of the provided views in the class seem to be able to do exactly what I was looking for.
I basically want to add my own background view, filling the whole cell. However, if I replace the backgroundView, the style from the grouped table view layout isn't displayed anymore. If I add a subview to backgroundView, the subview is not shown at all. If I add a subview to the contentView, I can't draw behind the accessory icon.
What am I missing?
Basically you can't change the backgorund of GroupedTable View.
Try using it with PlainTable.
and add the your backgroung image (of size = cellsize) to cellforRowAtIndex method.
You might want to take a look at this article:
"Easy custom UITableView Drawing"
In particular:
First: the UITableView does not itself
draw anything except the background.
To customize the background of a
UITableView, all you need to do is set
its backgroundColor to [UIColor
clearColor] and you can draw your own
background in a view behind the
UITableView.
Simply add the custom view as part of your contentView. Set a unique reuse identifier for that cell, configure it when you create it and from then on simply reset the data components (this is easiest to do if you create a custom cell controller class so that it can track all the parts and use setters/getters for the data).

How can I get the pinstripe background to show?

I'd like to use the pinstripe background that shows up in the Settings app and many other iPhone apps behind table views. Is is already included in some graphics library? How can I make it show up in a UIView or UITableView?
Pinstripe http://img.skitch.com/20090630-p783xugab8i9c7x2c63t3ped52.jpg
myView.backgroundColor = [UIColor groupTableViewBackgroundColor];
Just to stick with convention though, don't apply this background unless you're using tableviews that scroll as this type of background is semiotical to tableview scrolls.
You just have to use the "grouped" style on your table view.
As of iOS 6.0, this doesn't work anymore.