Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ViewController.swift
- // twoViewCollection
- //
- // Created by tops on 8/1/17.
- // Copyright © 2017 TOPS. All rights reserved.
- //
- import UIKit
- class ViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {
- @IBOutlet weak var myCollectionView: UICollectionView!
- var imgArray = ["01.jpg","02.jpg","03.jpeg","04.jpeg","05.jpeg","06.jpeg","07.jpg","08.jpg","09.jpg","10.jpg"]
- var nameArray = ["one","one","one","one","one","one","one","one","one","one"]
- override func viewDidLoad() {
- super.viewDidLoad()
- }
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- // Dispose of any resources that can be recreated.
- }
- @IBAction func btnTable(_ sender: UIButton)
- {
- let layout = UICollectionViewFlowLayout()
- layout.scrollDirection = .vertical
- let cellSize = CGSize(width:320 , height:150)
- layout.itemSize = cellSize
- layout.sectionInset = UIEdgeInsets(top: 1, left: 1, bottom: 1, right: 1)
- layout.minimumLineSpacing = 1.0
- layout.minimumInteritemSpacing = 1.0
- myCollectionView.setCollectionViewLayout(layout, animated: true)
- myCollectionView.reloadData()
- }
- @IBAction func btnGrid(_ sender: UIButton)
- {
- let layout = UICollectionViewFlowLayout()
- layout.scrollDirection = .horizontal
- let cellSize = CGSize(width:180 , height:180)
- layout.itemSize = cellSize
- layout.sectionInset = UIEdgeInsets(top: 1, left: 1, bottom: 1, right: 1)
- layout.minimumLineSpacing = 1.0
- layout.minimumInteritemSpacing = 1.0
- myCollectionView.setCollectionViewLayout(layout, animated: true)
- myCollectionView.reloadData()
- }
- func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
- {
- return imgArray.count
- }
- func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
- {
- let cell1 = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! cellVC
- cell1.img.image = UIImage(named: imgArray[indexPath.row])
- cell1.lbl.text = nameArray[indexPath.row]
- return cell1
- }
- }
- //
- // cellVC.swift
- // twoViewCollection
- //
- // Created by tops on 8/1/17.
- // Copyright © 2017 TOPS. All rights reserved.
- //
- import UIKit
- class cellVC: UICollectionViewCell {
- @IBOutlet weak var img: UIImageView!
- @IBOutlet weak var lbl: UILabel!
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement