TableView rounded corners and shadow

前端 未结 4 1062
隐瞒了意图╮
隐瞒了意图╮ 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:06

    Thanks to @beyowulf

    I have upgraded for me with Swift 2.2, to

    • set Border,
    • Rounded corner and
    • Drop shadow to the table view

      //for table view border
      tableView.layer.borderColor = UIColor .grayColor().CGColor
      tableView.layer.borderWidth = 1.0
      
      //for shadow
      let containerView:UIView = UIView(frame:self.tableView.frame)
      containerView.backgroundColor = UIColor.clearColor()
      containerView.layer.shadowColor = UIColor.lightGrayColor().CGColor
      containerView.layer.shadowOffset = CGSizeMake(-10, 10); //Left-Bottom shadow
      //containerView.layer.shadowOffset = CGSizeMake(10, 10); //Right-Bottom shadow
      containerView.layer.shadowOpacity = 1.0
      containerView.layer.shadowRadius = 2
      
      //for rounded corners
      tableView.layer.cornerRadius = 10
      tableView.layer.masksToBounds = true
      self.view.addSubview(containerView)
      containerView.addSubview(tableView)
      

    result looks like

提交回复
热议问题