Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Space between UITableView Cells [duplicate]

I have a UITableView which contains x amount of cells. However, I want to have 20 px distance between each cell. My tableview only contains one section.

I have googled around and searched the forum, but I couldn't find anything that works for my purpose.

Is it possible to set content offset to the cell, or the imageview inside the cell?

Can someone please help me?

like image 462
Magnus Avatar asked Feb 12 '12 22:02

Magnus


2 Answers

one alternate solution of this problem is just implement the method tableview:heightForFooterInSection like

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{

    return 5;
}

And then implement the tableView:ViewForFooterInSection like below //Returns a transparent footer actually.

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{ 

    UIView *view = [[UIView alloc]init]; 
    [view setAlpha:0.0F]; 
    return view; 

}
like image 81
Gyanendra Singh Avatar answered Sep 26 '22 01:09

Gyanendra Singh


Based on the follow-up in comments above, it sounds like you should use the UITableView backgroundView property to set your custom background image, then use a grouped table view with one cell per section. To me, this sounds like the quickest and easiest way to implement the type of UI you're describing.

Relevant portions of UITableView API documentation:

@property(nonatomic, readwrite, retain) UIView *backgroundView
...
- (NSInteger)numberOfRowsInSection:(NSInteger)section

And UITableViewDataSource protocol:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
like image 30
bneely Avatar answered Sep 24 '22 01:09

bneely