裡面有用到兩種不同Array寫法來存圖片
- class ViewController: UIViewController {
- @IBOutlet weak var btnPre: UIButton!
- @IBOutlet weak var btnNext: UIButton!
- @IBOutlet weak var labelName: UILabel!
- @IBOutlet weak var image: UIImageView!
- //兩種array方法
- var arrayImage = ["水上威尼斯","史特拉斯堡-2","科瑪", "新天鵝堡_繽紛","春露"]
- var pic: [UIImage] = [
- UIImage(named: "水上威尼斯")!,
- UIImage(named: "史特拉斯堡-2")!,
- UIImage(named: "科瑪")!,
- UIImage(named: "新天鵝堡_繽紛")!,
- UIImage(named: "春露")!
- ]
- var current:Int = 0
- var count:Int = 0
- override func viewDidLoad() {
- super.viewDidLoad()
- count = arrayImage.count
- //image.image = UIImage(named: "水上威尼斯")
- image.image = pic[0]
- labelName.text = arrayImage[0]
- }
- @IBAction func preClick(_ sender: UIButton) {
- current -= 1
- if current < 0 {
- current = count - 1
- }
- //image.image = UIImage(named:String(arrayImage[current]))
- image.image = pic[current]
- labelName.text = arrayImage[current]
- }
- @IBAction func nextClick(_ sender: UIButton) {
- current += 1
- if current == count {
- current = 0
- }
- //image.image = UIImage(named:String(arrayImage[current]))
- image.image = pic[current]
- labelName.text = arrayImage[current]
- }
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- }
- }
沒有留言:
張貼留言