How to create padding(spacing) between rows in tablview

后端 未结 5 763
情深已故
情深已故 2020-12-15 12:21

This isn\'t a duplicate I read the other questions regarding this and none of them gave me what i needed , I\'m creating a table view with custom cell and the style is group

相关标签:
5条回答
  • 2020-12-15 12:43

    in swift 5.1 :

       override func numberOfSections(in tableView: UITableView) -> Int {
           return 2
       }
       override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
           return 1
       }
    
       override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
           return 15
       }
    
       override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
           return 30
       } 
    
    0 讨论(0)
  • 2020-12-15 12:48

    Simply make the content of your cell clearcolor and give yourself padding by adding height. Add the background image (or color) of your cell however you'd like afterwards by inserting a new view or label of shorter height.

    This way you can maintain a table with multiple sections and multiple rows.

    0 讨论(0)
  • 2020-12-15 12:50

    Many ways to do it, but I found this is the simplest and easiest way to do so.

    Set UITableView style grouped. Then have two sections and each section has only one row. Replace your image in the row.

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
        //array is your db, here we just need how many they are
        return [array count];
    }
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
        return 1;
    }
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
        //place your image to cell
    }
    - (float)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
        //this is the space
        return 50;
    }
    
    0 讨论(0)
  • 2020-12-15 12:50

    You can do it in just 3 lines.

    First set gray color of your main view after that follow these lines.

    cell.separatorInset = UIEdgeInsetsMake(20, 20, 20, 20);
    cell.layer.borderWidth = 5;
    cell.layer.borderColor = [UIColor whiteColor].CGColor;
    
    0 讨论(0)
  • 2020-12-15 12:53

    1.First you can Increase heightForRowAtIndexPath size

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
        return 150;
    }
    
    1. Then add custom view on tableViewCell. then set view.frame according padding you want.
    0 讨论(0)
提交回复
热议问题