简体   繁体   中英

how to add row line for the tableview in ios

I want to display a table details in the tableView in the form of rows and columns as show below.

表格图片

I have implemented a UITableView in a ViewController , and added a Custom cell and displayed the data as shown

我已经实施

Now i dont want space between the cell .Instead i need a vertical line between the cell as in the image.

Here is my code

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

     AttendenceTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
     AttendenceTableViewCell*cell=[[AttendenceTableViewCell alloc]init];
     if (cell == nil) {
         cell = [[ AttendenceTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
     }
     cell.textLabel.textColor=[UIColor colorWithRed:0.24 green:0.67 blue:0.94 alpha:1.0];
     _attendenceTableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];

     cell.dateLabel.text=@"Date";
     cell.timeInLabel.text=@"in";
     cell.timeOutLabel.text=@"out";;
     cell.DurationLabel.text=@"duration";
     cell.statusLabel.text=@"status";
     [spinner stopAnimating];
     return cell;
}

how can i achieve it...?

请选择这样的原型单元或自定义单元,它将对您有帮助

You can change the height of the table cell by delegate method to remove space

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 45.0;
}

For line between data : 1. Add view for different label. 2. Add the label to the view. 3. Change the background color of the view.

add UIImageView on AttendenceTableViewCell *cell in cellForRowAtIndexPath. Each cell will have a vertical line

In AttendanceTableViewCell, you can add a view (programatically) like this(on your init method or in awakeFromNib):

CGFloat lineWidht = 2.00; // <- set the line width
UIColor *bgColor = [UIColor colorWithRed:200/255.0 green:199/255.0 blue:204/255.0 alpha:1.0];

CGRect horizontalLineFrame = CGRectMake(self.contentView.frame.size.width - lineWidht, 0, lineWidht, self.contentView.frame.size.height);

UIView *horizontalLine = [[UIView alloc] initWithFrame:horizontalLineFrame];
horizontalLine.backgroundColor = bgColor;
[self.contentView addSubview:horizontalLine];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM