Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- class CalendarViewController: UIViewController {
- @IBOutlet weak var calendarCollectionView: UICollectionView!
- override func viewDidLoad() {
- super.viewDidLoad()
- let layout = CalendarLayout()
- calendarCollectionView.collectionViewLayout = layout
- // calendarCollectionView.register(HeaderView.classForCoder(), forCellWithReuseIdentifier: "HeaderView")
- // Do any additional setup after loading the view.
- }
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- // Dispose of any resources that can be recreated.
- }
- /*
- // MARK: - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
- // Get the new view controller using segue.destinationViewController.
- // Pass the selected object to the new view controller.
- }
- */
- }
- class CalendarLayout: UICollectionViewLayout {
- override var collectionViewContentSize: CGSize {
- return super.collectionViewContentSize
- }
- override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
- return super.layoutAttributesForElements(in: rect)
- }
- override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
- return super.layoutAttributesForItem(at: indexPath)
- }
- override func layoutAttributesForSupplementaryView(ofKind elementKind: String, at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
- return super.layoutAttributesForSupplementaryView(ofKind: elementKind, at: indexPath)
- }
- override func layoutAttributesForDecorationView(ofKind elementKind: String, at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
- return super.layoutAttributesForDecorationView(ofKind: elementKind, at: indexPath)
- }
- override func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool {
- return true
- }
- }
- extension CalendarViewController: UICollectionViewDataSource {
- func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
- return 5
- }
- func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
- let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CalendarEventCell", for: indexPath) as? CalendarEventCell ?? CalendarEventCell()
- cell.titleLabel.text = "Title \(indexPath.row)"
- return cell
- }
- func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
- let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "HeaderView", for: indexPath) as? HeaderView ?? HeaderView()
- headerView.titleLabel.text = "header title"
- return headerView
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement