Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extension SelectPreferencesVC: UITableViewDelegate, UITableViewDataSource {
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- let sectionItem = sections[section]
- if sectionItem.isOpen {
- return sections[section].options.count + 1
- } else {
- return 1
- }
- }
- func numberOfSections(in tableView: UITableView) -> Int {
- sections.count
- }
- /*
- func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
- <#code#>
- }*/
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- if indexPath.row == 0 {
- let sectionData = sections[indexPath.section]
- guard let cell = tableView.dequeueReusableCell(withIdentifier: "preferenceSectionCell", for: indexPath) as? preferenceSectionCell else { return UITableViewCell() }
- cell.title.text = sectionData.name
- return cell
- } else {
- let rowData = sections[indexPath.section].options[indexPath.row - 1]
- let sectionData = sections[indexPath.section]
- debugPrint("Count : \(sectionData.options.count), last index \(indexPath.row)")
- guard let cell = tableView.dequeueReusableCell(withIdentifier: "preferenceRowCell", for: indexPath) as? preferenceRowCell else { return UITableViewCell() }
- cell.title.text = rowData
- cell.bottomLine.isHidden = sectionData.options.count == indexPath.row ? true : false
- return cell
- }
- }
- func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
- let radius: CGFloat = 17
- if tableView == preferenceTable {
- let sectionData = sections[indexPath.section]
- guard let cellNew = cell as? preferenceRowCell else { return }
- //Top Left Right Corners
- let maskPathTop = UIBezierPath(roundedRect: cellNew.bgView.bounds, byRoundingCorners: [.topLeft, .topRight], cornerRadii: CGSize(width: radius, height: radius))
- let shapeLayerTop = CAShapeLayer()
- shapeLayerTop.frame = cellNew.bgView.bounds
- shapeLayerTop.path = maskPathTop.cgPath
- //Bottom Left Right Corners
- let maskPathBottom = UIBezierPath(roundedRect: cellNew.bgView.bounds, byRoundingCorners: [.bottomLeft, .bottomRight], cornerRadii: CGSize(width: radius, height: radius))
- let shapeLayerBottom = CAShapeLayer()
- shapeLayerBottom.frame = cellNew.bgView.bounds
- shapeLayerBottom.path = maskPathBottom.cgPath
- //All Corners
- let maskPathAll = UIBezierPath(roundedRect: cellNew.bgView.bounds, byRoundingCorners: [.topLeft, .topRight, .bottomRight, .bottomLeft], cornerRadii: CGSize(width: radius, height: radius))
- let shapeLayerAll = CAShapeLayer()
- shapeLayerAll.frame = cellNew.bgView.bounds
- shapeLayerAll.path = maskPathAll.cgPath
- if (indexPath.row == 1)
- {
- //cellNew.bgView.layer.mask = shapeLayerTop
- cellNew.bgView.applyCornerRadius(17, maskedCorners: [.layerMaxXMinYCorner, .layerMinXMinYCorner])
- }
- else if sectionData.options.count == indexPath.row
- {
- cellNew.bgView.applyCornerRadius(17, maskedCorners: [.layerMinXMaxYCorner, .layerMaxXMaxYCorner])
- //cellNew.bgView.layer.mask = shapeLayerBottom
- }
- }
- }
- func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
- sections[indexPath.section].isOpen = !sections[indexPath.section].isOpen
- tableView.reloadSections([indexPath.section], with: .fade)
- }
- }
- struct Section {
- let name: String
- let options: [String]
- var isOpen = false
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement