-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathViewController.swift
67 lines (53 loc) · 2.54 KB
/
ViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//
// ViewController.swift
// Example
//
// Created by gwangbeom on 2017. 11. 27..
// Copyright © 2017년 Interactive-Studio. All rights reserved.
//
import UIKit
import ISPageControl
class ViewController: UIViewController {
@IBOutlet weak var collectionView: UICollectionView!
@IBOutlet weak var pageControl: ISPageControl!
var pageControl1: ISPageControl!
let images: [UIImage] = [#imageLiteral(resourceName: "bg1"), #imageLiteral(resourceName: "bg2"), #imageLiteral(resourceName: "bg3"), #imageLiteral(resourceName: "bg4"), #imageLiteral(resourceName: "bg5"), #imageLiteral(resourceName: "bg6"), #imageLiteral(resourceName: "bg7"), #imageLiteral(resourceName: "bg8")]
override func viewDidLoad() {
super.viewDidLoad()
pageControl.numberOfPages = images.count
let frame = CGRect(x: 0, y: 500, width: UIScreen.main.bounds.width, height: 100)
pageControl1 = ISPageControl(frame: frame, numberOfPages: images.count)
pageControl1.radius = 8
pageControl1.padding = 10
pageControl1.inactiveTintColor = UIColor.white.withAlphaComponent(0.4)
pageControl1.currentPageTintColor = UIColor.black
pageControl1.borderWidth = 1
pageControl1.borderColor = UIColor.black.withAlphaComponent(0.4)
view.addSubview(pageControl1)
}
}
extension ViewController: UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return images.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! ImageCell
cell.staImageView.image = images[indexPath.item]
return cell
}
}
extension ViewController: UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: UIScreen.main.bounds.width, height: 240)
}
}
extension ViewController: UIScrollViewDelegate {
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
let pageNumber = round(scrollView.contentOffset.x / scrollView.frame.size.width)
pageControl.currentPage = Int(pageNumber)
pageControl1.currentPage = Int(pageNumber)
}
}
class ImageCell: UICollectionViewCell {
@IBOutlet weak var staImageView: UIImageView!
}