Search code examples
swiftuicollectionviewshadow

Shadow for collectionView is not coming properly in swift


I am made calendar with collectionview, for calendar i am using JTAppleCalendar here i need shadow for collectionview so i have added shadow to collectionview like below

  override func viewDidLoad() {
    super.viewDidLoad()

    calendarView.layer.shadowColor = UIColor.black.cgColor
            calendarView.layer.shadowOffset = CGSize(width: 0, height: 1)
            calendarView.layer.shadowOpacity = 1
            calendarView.layer.shadowRadius = 1.0
            calendarView.layer.cornerRadius = 10
    
            calendarView.clipsToBounds = false
            calendarView.layer.masksToBounds = false

}

now the o/p: here if i scroll calendar for next month then i am getting un related dates(maybe next month dates) are coming right side.. how to remove that, and give perfect shadow to collectionview

enter image description here

if i didn't give shadow then i am not facing any problem while scrolling to next month.. only with shadow i am facing this issue

how to solve please do help.


Solution

  • calendarView.clipsToBounds = false is causing the views/cells outside current bounds to be visible as well.

    You should add your calendarView as a subview in a container UIView instance and try applying the shadow code to that view.