//
// ViewController.swift
// PickerView
//
// Created by stayfoolish on 2018. 8. 24..
// Copyright © 2018년 stayfoolish. All rights reserved.
//
import UIKit
class ViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {
let MAX_ARRAY_NUM = 12
let PICKER_VIEW_COLUMN = 1
var imageArray = [UIImage?]()
var imageFileName = ["1.jpg","2.jpg","3.jpg","4.jpg","5.jpg","6.jpg","7.jpg","8.jpg","9.jpg","10.jpg","11.jpg","12.jpg",]
@IBOutlet var pickerImage: UIPickerView!
@IBOutlet var lblImageFileNmae: UILabel!
@IBOutlet var imageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
for i in 0 ..< MAX_ARRAY_NUM{
let image = UIImage(named: imageFileName[i])
imageArray.append(image)
}
lblImageFileNmae.text = imageFileName[0]
imageView.image = imageArray[0]
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return PICKER_VIEW_COLUMN
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return imageFileName.count
}
/*
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int , forComponent component: Int ) -> String?{
return imageFileName[row]
}
*/
func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component:Int,
reusing view: UIView?) -> UIView {
let imageView = UIImageView(image:imageArray[row])
imageView.frame = CGRect(x: 0, y: 0, width: 100, height: 150)
return imageView
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int ){
lblImageFileNmae.text = imageFileName[row]
imageView.image = imageArray[row]
}
}
'Swift > 기초&문법' 카테고리의 다른 글
스위프트 swift imagepicker delegate 사진선택 (0) | 2018.08.28 |
---|---|
스위프트 swift music player 음악재생 앱 (0) | 2018.08.27 |
스위프트 swift 데이트 피커 사용해 날짜 선택하는 앱 (0) | 2018.08.24 |
스위프트 swift 원하는 이미지 화면 출력 앱 (0) | 2018.08.22 |
스위프트 swift 열거형 enum (0) | 2018.08.21 |