7

Please refer to this picture below:

Result

I want to customize a UITableView.

I achieved applying image background for it using tableView.backgroundView.

Now I want to add left indent/margin to every row as the example picture. Then I want to reduce their width and centerize them.

Could I achieve these? Any help is appreciated :)

Shinigamae
  • 854
  • 3
  • 18
  • 35
  • I'd say that the better way is to customize the UITableViewCell... There are a lot of tutorial around the web. – Larme Nov 13 '12 at 10:13
  • Why don't you just set the frame of your UITableView ? And yeah, if you want to indent, just customize trough UITableViewCell. – Snaker Nov 13 '12 at 10:13
  • are you added the tableView to ypur project or choose the navigation template ? – Midhun MP Nov 13 '12 at 10:13
  • @Snaker I want cells to stay inside a specific position inside my background image. If I set UITableView, would it affect my backgroundView as well? – Shinigamae Nov 13 '12 at 10:15
  • @MidhunMP I added UITableView from Object Library, then add items programmatically. My ViewController is implemented UITableViewDataSource and UITableViewDelegate. – Shinigamae Nov 13 '12 at 10:17
  • @Larme I stuck hours on Google to find a way to do this :( – Shinigamae Nov 13 '12 at 10:17
  • If you set the background to the UITableView, yeah, by modifying the UITableView frame, you will also modify the background. – Snaker Nov 13 '12 at 10:17
  • @Snaker so the setFrame solution won't work for me :) – Shinigamae Nov 13 '12 at 10:18
  • 2
    Then you might take jimpic's answer : Setting the cells as tranparent. Concerning the indentation, have you taken a look at [this](http://stackoverflow.com/questions/2502822/indentationlevelforrowatindexpath-not-indenting-custom-cell) ? – Snaker Nov 13 '12 at 10:25

1 Answers1

24

You could use a transparent view for your cells and center your content inside that cell. Or you can use

- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath

for the indentation part.

jimpic
  • 5,360
  • 2
  • 28
  • 37