Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MenuBar: UIView, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {
- lazy var collectionView: UICollectionView = {
- let layout = UICollectionViewFlowLayout()
- let cv = UICollectionView(frame: .zero, collectionViewLayout: layout)
- cv.backgroundColor = .lightGray
- cv.dataSource = self
- cv.delegate = self
- return cv
- }()
- let cellId = "cellId"
- let imageNames = ["Plan", "folder", "list", "people", "plancorrection"]
- override init(frame: CGRect) {
- super.init(frame: frame)
- collectionView.register(MenuCell.self, forCellWithReuseIdentifier: cellId)
- addSubview(collectionView)
- addConstraintsWithFormat("H:|[v0]|", views: collectionView)
- addConstraintsWithFormat("V:|[v0(200)]|", views: collectionView)
- let selectedIndexPath = IndexPath(item: 0, section: 0)
- collectionView.selectItem(at: selectedIndexPath, animated: false, scrollPosition: .bottom)
- }
- func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
- return 5
- }
- func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
- let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath) as! MenuCell
- cell.imageView.image = UIImage(named: imageNames[indexPath.item])?.withRenderingMode(.alwaysTemplate)
- cell.tintColor = .white
- return cell
- }
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
- return CGSize(width: frame.width / 5, height: frame.height)
- }
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
- return 0
- }
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
- }
- class MenuCell: CustomMenuBarBaseCell {
- let imageView: UIImageView = {
- let iv = UIImageView()
- iv.image = UIImage(named: "Plan")?.withRenderingMode(.alwaysTemplate)
- iv.tintColor = .gray
- return iv
- }()
- override var isHighlighted: Bool {
- didSet {
- imageView.tintColor = isHighlighted ? UIColor.white : UIColor.rgb(red: 91, green: 14, blue: 13)
- }
- }
- // override var isSelected: Bool {
- // didSet {
- // imageView.tintColor = isSelected ? UIColor.white : UIColor.rgb(red: 91, green: 14, blue: 13)
- // }
- // }
- override func setupViews() {
- super.setupViews()
- addSubview(imageView)
- addConstraintsWithFormat("H:[v0(28)]", views: imageView)
- addConstraintsWithFormat("V:[v0(28)]", views: imageView)
- addConstraint(NSLayoutConstraint(item: imageView, attribute: .centerX, relatedBy: .equal, toItem: self, attribute: .centerX, multiplier: 1, constant: 0))
- addConstraint(NSLayoutConstraint(item: imageView, attribute: .centerY, relatedBy: .equal, toItem: self, attribute: .centerY, multiplier: 1, constant: 0))
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement