TableView rounded corners and shadow

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

    The RDC's answer is good, but for me the result didnt resolve my case, follow is my fix :

    //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)
    //dont use clear color,fit blue color
    containerView.backgroundColor = UIColor.blueColor()
    //shadow view also need cornerRadius
    containerView.layer.cornerRadius = 10
    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)
    self.view.addSubview(tableView)
    

提交回复
热议问题