Guest User

Untitled

a guest
Feb 16th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. import UIKit
  2.  
  3.  
  4.  
  5. class HomeController: UICollectionViewController,
  6. UICollectionViewDelegateFlowLayout {
  7.  
  8.  
  9. var Legends: [Legend] = {
  10. var select1 = Legend()
  11. select1.thumbnailImageName = "select1thumbnail"
  12. var select2 = Legend()
  13. select2.thumbnailImageName = "select2humbnail"
  14.  
  15. return[select1, select2]
  16. }()
  17.  
  18. override func viewDidLoad() {
  19. super.viewDidLoad()
  20. navigationItem.title = "Choose Selection"
  21. collectionView.backgroundView = UIImageView(image: UIImage(named: "backgroundlogo"))
  22. collectionView?.register(VideoCell.self, forCellWithReuseIdentifier: "cellId")
  23. collectionView.dataSource = self
  24. collectionView.delegate = self
  25.  
  26.  
  27.  
  28. }
  29.  
  30. override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  31. return Legends.count
  32.  
  33. }
  34. override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  35. let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellId", for: indexPath) as! VideoCell
  36.  
  37. cell.legend = Legends[indexPath.item]
  38. return cell
  39.  
  40. }
  41.  
  42. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
  43. return CGSize(width:view.frame.height, height: 150)
  44. }
  45.  
  46. func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
  47. return 0
  48.  
  49. }
  50.  
  51. override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
  52. let select2VC = UIViewController()
  53. navigationController?.navigationBar.tintColor = UIColor.white
  54. navigationController?.pushViewController(select2VC, animated: true)
  55.  
  56. print("selcected")
  57.  
  58.  
  59. }
  60.  
  61. }
  62.  
  63. import UIKit
  64.  
  65.  
  66.  
  67. class VideoCell: UICollectionViewCell {
  68.  
  69. var legend: Legend? {
  70. didSet {
  71. thumbnailImageView.image = UIImage(named: (legend?.thumbnailImageName)!)
  72.  
  73. }
  74. }
  75.  
  76. override init(frame: CGRect) {
  77. super.init(frame: frame)
  78. setupViews()
  79. }
  80.  
  81. required init?(coder aDecoder: NSCoder) {
  82. fatalError("init(coder:) has not been implemented")
  83. }
  84.  
  85. let thumbnailImageView: UIImageView = {
  86. let imageView = UIImageView()
  87. imageView.backgroundColor = UIColor.darkGray
  88. imageView.image = UIImage(named:"bgcolor")
  89. imageView.contentMode = .scaleAspectFit
  90. imageView.clipsToBounds = true
  91. imageView.translatesAutoresizingMaskIntoConstraints = false
  92. return imageView
  93. }()
  94.  
  95. func setupViews() {
  96. addSubview(thumbnailImageView)
  97.  
  98. addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-16-[v0]-16-|", options: NSLayoutConstraint.FormatOptions(), metrics: nil, views: ["v0": thumbnailImageView]))
  99. addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-1-[v0]-0-|", options: NSLayoutConstraint.FormatOptions(), metrics: nil, views: ["v0": thumbnailImageView]))
  100.  
  101. }
  102.  
  103.  
  104.  
  105. }
  106.  
  107. import UIKit
  108.  
  109. class Legend: NSObject {
  110.  
  111. var thumbnailImageName: String?
  112.  
  113. }
Add Comment
Please, Sign In to add comment