UITableViewCell: rounded corners and shadow

前端 未结 14 1398
故里飘歌
故里飘歌 2020-12-02 05:05

I\'m changing the width of a UITableViewCell so that the cell is smaller but the user can still scroll along the edges of the tableview.

override func layout         


        
14条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-02 05:13

    create a UIVIEW inside cell's content view "backView" and add an outlet of backView to cell class then add these lines of code to awakeFromNib()

    self.backView.layer.cornerRadius = 28
    self.backView.clipsToBounds = true 
    

    the corner radius depends on your design... the add these code to cellForRowAt function

    cell.layer.shadowColor = UIColor.black.cgColor
    cell.layer.shadowOffset = CGSize(width: 0, height: 0)
    cell.layer.shadowOpacity = 0.6
    

    and set the cell view background color to clear color

    Don't forget to add a little space between 4 sides of the cell and the backView you just added inside cell contentView in StoryBoard

    hope you liked it

提交回复
热议问题