TableView rounded corners and shadow

前端 未结 4 1048
隐瞒了意图╮
隐瞒了意图╮ 2020-12-08 05:35

I have a tableview with three rows. I am trying to make the table rows have rounded corners and also a shadow effect around the entire tableview. For some reason, I cannot m

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-08 06:24

    i tried above solution but in my application tableview didSelectRowAt was not working.

    use this Extension for UITabeleView for corner for shadow

    //if u want shadow for all side use (shadowOffset = .zero)

    extension UITableView {
        func addCorner(){
            self.layer.cornerRadius = 15
            self.clipsToBounds = true
        }
    
        func addShadow(){
            self.layer.shadowColor = UIColor.lightGray.cgColor
            self.layer.shadowRadius = 5
            self.layer.shadowOpacity = 0.5
            self.layer.shadowOffset = .zero
            self.layer.masksToBounds = false
        }
    }
    

    How to use::

       self.tableView.addCorner()
       self.tableView.addShadow()
    

提交回复
热议问题