Created
February 26, 2019 17:28
-
-
Save ayoub-9/718ca6f99406ef75c56dce36350fdc99 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Explore.swift | |
// IINII | |
// | |
// Created by Ayoub Alrshidi on 21/06/1440 AH. | |
// Copyright © 1440 Ayoub Alrshidi. All rights reserved. | |
// | |
import UIKit | |
class Explore: UIViewController,UICollectionViewDataSource, UICollectionViewDelegate,UICollectionViewDelegateFlowLayout { | |
//MARK: - IDs | |
let ImageCellID = "imageCell" | |
let albumId = "CellId" | |
//MARK: - ARRY IMAGES | |
let imagesArray = ["image1", "image2", "image3", "image4", "image5"] | |
let albumsArray = ["album1", "album2", "album3", "album4", "album5", "album6", "album7", "album8", "album9"] | |
let collectionView: UICollectionView = { | |
let layout = UICollectionViewFlowLayout() | |
layout.scrollDirection = .vertical | |
layout.minimumInteritemSpacing = 1 | |
layout.minimumLineSpacing = 10 | |
let cv = UICollectionView(frame: .zero, collectionViewLayout: layout) | |
cv.backgroundColor = .clear | |
return cv | |
}() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
SetupViews() | |
} | |
func SetupViews(){ | |
view.backgroundColor = .lightGray | |
//register cell class | |
collectionView.register(ImagesCell.self, forCellWithReuseIdentifier: ImageCellID) | |
collectionView.register(AlbumaCell.self, forCellWithReuseIdentifier: albumId) | |
//MARK: - Add CollectonView List to View | |
collectionView.delegate = self | |
collectionView.dataSource = self | |
view.addSubview(collectionView) | |
collectionView.setAnchor(top: view.topAnchor, left: view.leftAnchor, bottom: view.bottomAnchor, right: view.rightAnchor, paddingTop: 0, paddingLeft: 0, paddingBottom: 0, paddingRight: 0) | |
} | |
func numberOfSections(in collectionView: UICollectionView) -> Int { | |
return 2 | |
} | |
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { | |
if section == 1 { | |
return 20 | |
} | |
return 1 | |
} | |
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { | |
if indexPath.section == 1 { | |
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: albumId, for: indexPath) as! AlbumaCell | |
return cell | |
} | |
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: ImageCellID, for: indexPath) as! ImagesCell | |
return cell | |
} | |
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { | |
if indexPath.section == 1 { | |
let itemSize = UIScreen.main.bounds.width/3 - 3 | |
return CGSize(width: itemSize, height: 230) | |
} | |
//next Section | |
return CGSize(width: 400, height: 200) | |
} | |
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets { | |
if section == 1 { | |
return UIEdgeInsets(top: 1, left: 1, bottom: 1, right: 1) | |
} | |
return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0) | |
} | |
} | |
class ImagesCell: UICollectionViewCell, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout { | |
var Images: [String]? { | |
didSet{ | |
collectionView.reloadData() | |
} | |
} | |
//MARK: - IDs | |
let cellId = "cell" | |
let collectionView: UICollectionView = { | |
let layout = UICollectionViewFlowLayout() | |
layout.minimumLineSpacing = 30 | |
layout.scrollDirection = .horizontal | |
let cv = UICollectionView(frame: .zero, collectionViewLayout: layout) | |
cv.backgroundColor = .clear | |
return cv | |
}() | |
override init(frame: CGRect) { | |
super.init(frame: frame) | |
setup() | |
//MARK: - regsiter cell class | |
collectionView.register(iconsCell.self, forCellWithReuseIdentifier: cellId) | |
} | |
func setup(){ | |
backgroundColor = .red | |
//MARK: - CollectionView This From Cell file | |
addSubview(collectionView) | |
collectionView.setAnchor(top: topAnchor, left: leftAnchor, bottom: bottomAnchor, right: rightAnchor, paddingTop: 0, paddingLeft: 0, paddingBottom: 0, paddingRight: 0) | |
collectionView.delegate = self | |
collectionView.dataSource = self | |
collectionView.showsHorizontalScrollIndicator = false | |
} | |
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! iconsCell | |
return cell | |
} | |
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { | |
return CGSize(width: 200, height: frame.height - 20 ) | |
} | |
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets { | |
return UIEdgeInsets(top: 0, left: 14, bottom: 0, right: 14) | |
} | |
required init?(coder aDecoder: NSCoder) { | |
fatalError("init(coder:) has not been implemented") | |
} | |
private class iconsCell: UICollectionViewCell { | |
//MARK: Properties | |
let ImageView: UIImageView = { | |
let iv = UIImageView() | |
iv.backgroundColor = .lightGray | |
iv.contentMode = .scaleToFill | |
iv.clipsToBounds = true | |
iv.layer.cornerRadius = 15 | |
return iv | |
}() | |
override init(frame: CGRect) { | |
super.init(frame: frame) | |
setup() | |
} | |
func setup(){ | |
addSubview(ImageView) | |
ImageView.setAnchor(top: topAnchor, left: leftAnchor, bottom: bottomAnchor, right: rightAnchor, paddingTop: 0, paddingLeft: 0, paddingBottom: 0, paddingRight: 0) | |
} | |
required init?(coder aDecoder: NSCoder) { | |
fatalError("init(coder:) has not been implemented") | |
} | |
} | |
} | |
class AlbumaCell: UICollectionViewCell { | |
var Images2: [String]? { | |
didSet{ | |
} | |
} | |
override init(frame: CGRect) { | |
super.init(frame: frame) | |
backgroundColor = .green | |
} | |
required init?(coder aDecoder: NSCoder) { | |
fatalError("init(coder:) has not been implemented") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
//
// Extensions.swift
// Sections
//
// Created by Pavel Bogart on 2/10/17.
// Copyright © 2017 Pavel Bogart. All rights reserved.
//
import UIKit
extension UIView {
}