pageControl



페이지 컨트롤 자체는 objC랑 사용법이 거의 바뀌지 않은 것 같다. 다행.


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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//
//  ViewController_pageControl.swift
//  testSwift2
//
//  Created by Eteris on 2018. 5. 4..
//  Copyright © 2018년 Eteris. All rights reserved.
//
 
import UIKit
 
class ViewController_pageControl: UIViewController {
 
    @IBOutlet weak var iv: UIImageView!
    @IBOutlet weak var pageControl: UIPageControl!
    
    
    var array_imageData : Array<ImageData>?;
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        NSLog("===== ViewController_pageControl viewDidLoad");
 
        // Do any additional setup after loading the view.
        
        // ImageData
        array_imageData = Array<ImageData>();
        
        for index in 0 ... 2
        {
            
            var imageData : ImageData = ImageData.init(name: String(index+1+ ".jpg", desc: "desc " + String(index+1));
            
            array_imageData?.append(imageData);
        }
        
        for index in 0 ..< array_imageData!.count
        {
            NSLog("index [" + String(index) + "] imageName : [" + array_imageData![index].imageName + "] / imageDesc : [" + array_imageData![index].imageDescription + "]");
        }
    }
    
    override func viewWillAppear(_ animated: Bool) {
        NSLog("===== ViewController_pageControl viewWillAppear");
    }
    
    override func viewDidAppear(_ animated: Bool) {
        NSLog("===== ViewController_pageControl viewDidAppear");
        
        // 페이지 컨트롤 초기화
        pageControl.numberOfPages = array_imageData!.count;
        pageControl.currentPage = 0;
        pageControl.pageIndicatorTintColor = UIColor.green;
        pageControl.currentPageIndicatorTintColor = UIColor.red;
        
        iv.image = UIImage.init(named: array_imageData![pageControl.currentPage].imageName);
    }
 
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    // action - pageControl valueChanged
    @IBAction func pageControlAction_valueChanged(_ sender: Any) {
        
        NSLog("===== ViewController_pageControl pageControlAction_valueChanged");
        
        iv.image = UIImage.init(named: array_imageData![pageControl.currentPage].imageName);
        
    }
    
    /*
    // MARK: - Navigation
    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */
 
}
 
cs


'Developer > Swift' 카테고리의 다른 글

pushViewController (code)  (0) 2018.05.06
tableview 커스텀셀 (customcell)  (0) 2018.05.06
pageControl  (0) 2018.05.04
NavigationController / NavigationItem  (0) 2018.05.02
AlertDialog and Response Function  (0) 2018.05.02
pickerview with CustomView  (0) 2018.04.30

이 글을 공유하기


댓글(0)

Designed by CMSFactory.NET