Skip to content

Instantly share code, notes, and snippets.

@DonMag
Created May 12, 2017 19:53
Show Gist options
  • Select an option

  • Save DonMag/329dd7a72a10f50e782532b67d4b0f8f to your computer and use it in GitHub Desktop.

Select an option

Save DonMag/329dd7a72a10f50e782532b67d4b0f8f to your computer and use it in GitHub Desktop.
//
// MenuBarCVViewController.swift
// verytmp
//
// Created by Don Mag on 5/12/17.
// Copyright © 2017 DonMag. All rights reserved.
//
import UIKit
class MenuBarCVViewController: UIViewController {
let menuBar : MenuBar = {
let mb = MenuBar()
mb.translatesAutoresizingMaskIntoConstraints = false
return mb
}()
func setupMenuBar() {
view.addSubview(menuBar)
menuBar.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
menuBar.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
menuBar.widthAnchor.constraint(equalTo: view.widthAnchor).isActive = true
menuBar.heightAnchor.constraint(equalToConstant: 200).isActive = true
}
override func viewDidLoad() {
super.viewDidLoad()
setupMenuBar()
}
}
class MenuBarCell: UICollectionViewCell {
}
class MenuBar : UIView, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
let cellID : String = "menuCell"
lazy var collectionView : UICollectionView = {
let cv : UICollectionView = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout())
cv.backgroundColor = .red
cv.translatesAutoresizingMaskIntoConstraints = false
//cv.isScrollEnabled = false
cv.delegate = self
cv.dataSource = self
return cv
}()
override init(frame: CGRect) {
super.init(frame: frame)
setupCollectionView()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setupCollectionView()
}
func setupCollectionView() {
addSubview(collectionView)
collectionView.register(MenuBarCell.self, forCellWithReuseIdentifier: cellID)
// setup menuBar constraints
collectionView.topAnchor.constraint(equalTo: self.topAnchor).isActive = true
collectionView.leftAnchor.constraint(equalTo: self.leftAnchor).isActive = true
collectionView.widthAnchor.constraint(equalTo: self.widthAnchor).isActive = true
collectionView.heightAnchor.constraint(equalTo: self.heightAnchor).isActive = true
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellID, for: indexPath)
cell.backgroundColor = .white
return cell
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 4
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment