Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. //
  2. // ViewController.swift
  3. // twoViewCollection
  4. //
  5. // Created by tops on 8/1/17.
  6. // Copyright © 2017 TOPS. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10.  
  11. class ViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {
  12.  
  13.  
  14. @IBOutlet weak var myCollectionView: UICollectionView!
  15.  
  16.  
  17. var imgArray = ["01.jpg","02.jpg","03.jpeg","04.jpeg","05.jpeg","06.jpeg","07.jpg","08.jpg","09.jpg","10.jpg"]
  18. var nameArray = ["one","one","one","one","one","one","one","one","one","one"]
  19.  
  20. override func viewDidLoad() {
  21. super.viewDidLoad()
  22.  
  23. }
  24.  
  25. override func didReceiveMemoryWarning() {
  26. super.didReceiveMemoryWarning()
  27. // Dispose of any resources that can be recreated.
  28. }
  29.  
  30.  
  31. @IBAction func btnTable(_ sender: UIButton)
  32. {
  33. let layout = UICollectionViewFlowLayout()
  34. layout.scrollDirection = .vertical
  35.  
  36. let cellSize = CGSize(width:320 , height:150)
  37.  
  38. layout.itemSize = cellSize
  39. layout.sectionInset = UIEdgeInsets(top: 1, left: 1, bottom: 1, right: 1)
  40. layout.minimumLineSpacing = 1.0
  41. layout.minimumInteritemSpacing = 1.0
  42. myCollectionView.setCollectionViewLayout(layout, animated: true)
  43.  
  44. myCollectionView.reloadData()
  45.  
  46. }
  47.  
  48. @IBAction func btnGrid(_ sender: UIButton)
  49. {
  50. let layout = UICollectionViewFlowLayout()
  51. layout.scrollDirection = .horizontal
  52.  
  53.  
  54. let cellSize = CGSize(width:180 , height:180)
  55.  
  56. layout.itemSize = cellSize
  57. layout.sectionInset = UIEdgeInsets(top: 1, left: 1, bottom: 1, right: 1)
  58. layout.minimumLineSpacing = 1.0
  59. layout.minimumInteritemSpacing = 1.0
  60.  
  61.  
  62.  
  63. myCollectionView.setCollectionViewLayout(layout, animated: true)
  64. myCollectionView.reloadData()
  65. }
  66.  
  67. func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
  68. {
  69. return imgArray.count
  70. }
  71. func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
  72. {
  73. let cell1 = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! cellVC
  74. cell1.img.image = UIImage(named: imgArray[indexPath.row])
  75. cell1.lbl.text = nameArray[indexPath.row]
  76. return cell1
  77. }
  78.  
  79. }
  80.  
  81.  
  82.  
  83. //
  84. // cellVC.swift
  85. // twoViewCollection
  86. //
  87. // Created by tops on 8/1/17.
  88. // Copyright © 2017 TOPS. All rights reserved.
  89. //
  90.  
  91. import UIKit
  92.  
  93. class cellVC: UICollectionViewCell {
  94.  
  95.  
  96.  
  97. @IBOutlet weak var img: UIImageView!
  98.  
  99.  
  100.  
  101. @IBOutlet weak var lbl: UILabel!
  102.  
  103.  
  104.  
  105.  
  106.  
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement