Parv Bhasker
Parv Bhasker

Reputation: 1901

How to set header exectaly above the particular content in tableview

I used checkbox and switches in my custom tableview cell. But as shown in the image i need to place the header at the proper place above the checkbox and switch.

How should i suppose to do this.

Thanks in advance.

how to place header above the checkbox and switch.

Upvotes: 1

Views: 88

Answers (2)

Pushpendra
Pushpendra

Reputation: 1521

Follow these steps for achieving your task.

  1. Add a UITableViewController to your storyboard
  2. Create two cell in your UITableView
  3. First cell identifier take as headerCell and second cell identifier take as listCell
  4. Take two label inside your first cell
  5. Now it's time to set constraint first controller click on right label and drag it to first cell and set it to vertical center.
  6. Now click on same label and set its constraint from left as 8 as shown in image. Check It
  7. Set same for Label two which is Selectable.
  8. Now comes with the new cell which is called as listCell see the image and set all constraint as shown in image. check this
  9. Also don't forget to set width to both label which in header cell.

Upvotes: 1

Lawliet
Lawliet

Reputation: 3499

You would probably need a custom tableview header as well.

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    return YOUR_CUSTOM_HEADER_VIEW
}

enter image description here

Upvotes: 1

Related Questions