Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- class HomeController: UICollectionViewController,
- UICollectionViewDelegateFlowLayout {
- var Legends: [Legend] = {
- var select1 = Legend()
- select1.thumbnailImageName = "select1thumbnail"
- var select2 = Legend()
- select2.thumbnailImageName = "select2humbnail"
- return[select1, select2]
- }()
- override func viewDidLoad() {
- super.viewDidLoad()
- navigationItem.title = "Choose Selection"
- collectionView.backgroundView = UIImageView(image: UIImage(named: "backgroundlogo"))
- collectionView?.register(VideoCell.self, forCellWithReuseIdentifier: "cellId")
- collectionView.dataSource = self
- collectionView.delegate = self
- }
- override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
- return Legends.count
- }
- override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
- let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellId", for: indexPath) as! VideoCell
- cell.legend = Legends[indexPath.item]
- return cell
- }
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
- return CGSize(width:view.frame.height, height: 150)
- }
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
- return 0
- }
- override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
- let select2VC = UIViewController()
- navigationController?.navigationBar.tintColor = UIColor.white
- navigationController?.pushViewController(select2VC, animated: true)
- print("selcected")
- }
- }
- import UIKit
- class VideoCell: UICollectionViewCell {
- var legend: Legend? {
- didSet {
- thumbnailImageView.image = UIImage(named: (legend?.thumbnailImageName)!)
- }
- }
- override init(frame: CGRect) {
- super.init(frame: frame)
- setupViews()
- }
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
- let thumbnailImageView: UIImageView = {
- let imageView = UIImageView()
- imageView.backgroundColor = UIColor.darkGray
- imageView.image = UIImage(named:"bgcolor")
- imageView.contentMode = .scaleAspectFit
- imageView.clipsToBounds = true
- imageView.translatesAutoresizingMaskIntoConstraints = false
- return imageView
- }()
- func setupViews() {
- addSubview(thumbnailImageView)
- addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-16-[v0]-16-|", options: NSLayoutConstraint.FormatOptions(), metrics: nil, views: ["v0": thumbnailImageView]))
- addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-1-[v0]-0-|", options: NSLayoutConstraint.FormatOptions(), metrics: nil, views: ["v0": thumbnailImageView]))
- }
- }
- import UIKit
- class Legend: NSObject {
- var thumbnailImageName: String?
- }
Add Comment
Please, Sign In to add comment