-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUIPageControllerVC.swift
59 lines (47 loc) · 2.14 KB
/
UIPageControllerVC.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
//
// UIPageControllerViewController.swift
// UIKitDemo
//
// Created by Kyrie Miyajima on 2015/02/09.
// Copyright (c) 2015年 Kirie Miyajima. All rights reserved.
//
import UIKit
class UIPageControllerViewController: UIViewController, UIScrollViewDelegate {
var pageControl:UIPageControl!
var scrollView:UIScrollView!
override func viewDidLoad() {
let width = self.view.frame.maxX
let height = self.view.frame.maxY;
self.title = "UIPageControll";
self.view.backgroundColor = UIColor.whiteColor();
scrollView = UIScrollView(frame: self.view.frame);
let pageSize = 4;
scrollView.showsHorizontalScrollIndicator = false;
scrollView.showsVerticalScrollIndicator = false;
scrollView.pagingEnabled = true;
scrollView.delegate = self;
scrollView.contentSize = CGSizeMake(CGFloat(pageSize) * width, 0);
self.view.addSubview(scrollView);
for i in 0 ..< pageSize {
let myLabel:UILabel = UILabel(frame: CGRectMake(CGFloat(i) * width + width/2 - 40, height/2 - 40, 80, 80));
myLabel.backgroundColor = UIColor.greenColor();
myLabel.textColor = UIColor.whiteColor();
myLabel.textAlignment = NSTextAlignment.Center;
//myLabel.layer.position = CGPoint(x: self.view.bounds.width/2, y: 200);
myLabel.text = String(i+1);
myLabel.font = UIFont.systemFontOfSize(40);
scrollView.addSubview(myLabel);
}
pageControl = UIPageControl(frame: CGRectMake(0, self.view.frame.maxY - 100, width, 50));
pageControl.backgroundColor = UIColor.orangeColor();
pageControl.numberOfPages = pageSize;
pageControl.currentPage = 0;
pageControl.userInteractionEnabled = false;
self.view.addSubview(pageControl);
}
func scrollViewDidEndDecelerating(scrollView: UIScrollView) {
if fmod(scrollView.contentOffset.x, scrollView.frame.maxX) == 0{
pageControl.currentPage = Int(scrollView.contentOffset.x / scrollView.frame.maxX);
}
}
}