iwheelbuy / SquareMosaicLayout

An extandable mosaic UICollectionViewLayout with a focus on extremely flexible customizations :large_orange_diamond:
MIT License
259 stars 19 forks source link

set shadow for section #10

Closed MuhammadEhsanMirzaei closed 5 years ago

MuhammadEhsanMirzaei commented 5 years ago

Hi, I set shadow for section but doesn't effect on section `func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView { switch kind { case SquareMosaicLayoutSectionBacker: let view: UICollectionReusableView = collectionView.dequeueSupplementary(kind, indexPath: indexPath, kind: kind) view.layer.backgroundColor = UIColor.white.cgColor view.layer.roundedAllCorner(width: 5, height: 5) view.layer.borderColor = UIColor.clear.cgColor view.layer.shadowColor = UIColor.lightGray.cgColor view.layer.shadowOffset = CGSize(width: 13, height: 13) view.layer.shadowOpacity = 15 view.layer.shadowRadius = 12 view.layer.masksToBounds = false view.masksToBounds = false return view case SquareMosaicLayoutSectionHeader: let view: UICollectionReusableView = collectionView.dequeueSupplementary(kind, indexPath: indexPath, kind: kind) view.layer.backgroundColor = UIColor.clear.cgColor

        let label = UILabel()
        label.text = "header"
        label.font = UIFont.systemFont(ofSize: 20)
        label.textAlignment = .center
        label.frame = view.bounds
        view.addSubview(label)

        return view
    default:
        fatalError()
    }
}`
iwheelbuy commented 5 years ago

Hi. Have you tried your shadow on Example project?

MuhammadEhsanMirzaei commented 5 years ago

yes I did

Hi. Have you tried your shadow on Example project?

iwheelbuy commented 5 years ago

And what was the result? (: Try adding a subview on top of any UICollectionReusableView. Make sure that the subview is not of the same size as UICollectionReusableView (5-10 points insets). Also make sure that subview clipsToBounds = false. Then apply your shadow to a subview.

MuhammadEhsanMirzaei commented 5 years ago

so in which delegate I must add a subView?

iwheelbuy commented 5 years ago

You add a subview on supplementary view. To achieve this you should create your own supplementary view (link) Then register it: view.register(DecorationView.self, identifier: SquareMosaicLayoutSectionBacker, kind: SquareMosaicLayoutSectionBacker)

MuhammadEhsanMirzaei commented 5 years ago

thanks it's worked