Last active
August 29, 2017 01:08
-
-
Save kwoncharles/040b8a4e04084b3fcd7b8c3f62d1a277 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ViewController.swift | |
// PickerView | |
// | |
// Created by Kwoncheol on 26/08/2017. | |
// Copyright © 2017 Kwoncheol. All rights reserved. | |
// | |
import UIKit | |
class ViewController: UIViewController,UIPickerViewDelegate { | |
let MAX_ARRAY_NUM = 9 | |
let PICKER_VIEW_COLUMN = 1 | |
let PICKER_VIEW_HEIGHT:CGFloat=80 | |
var imageArray = [UIImage]() | |
var imageFileName = ["mhl1.jpg", "mhl2.jpg", "mhl3.jpg","mhl4.jpg","mhl5.jpg","mhl6.jpg","mhl7.jpg","mhl8.jpg","mhl9.jpg"] | |
@IBOutlet weak var imageView: UIImageView! | |
@IBOutlet weak var pickerImage: UIPickerView! | |
@IBOutlet weak var lblImageFileName: UILabel! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view, typically from a nib. | |
//lblImageFileName.text = imageFileName[0] | |
for i in 0..<MAX_ARRAY_NUM { | |
let image = UIImage(named: imageFileName[i]) | |
imageArray.append(image!) | |
} | |
lblImageFileName.text = imageFileName[0] | |
imageView.image = imageArray[0] | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
// Dispose of any resources that can be recreated. | |
} | |
//return the number of 'columns' to display. | |
func numberOfComponets(in pickerView: UIPickerView!) -> Int { | |
return PICKER_VIEW_COLUMN | |
} | |
func pickerView(_ pickerView: UIPickerView, rowHeightForComponent component:Int) -> CGFloat { | |
return PICKER_VIEW_HEIGHT | |
} | |
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.init(x:0, y:0, width:100, height:150) | |
return imageView | |
} | |
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) { | |
lblImageFileName.text = imageFileName[row] | |
imageView.image = imageArray[row] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment