<--! [iOS] 이미지 갤러리 간략소스 -->

[iOS] 이미지 갤러리 간략소스

필그램

·

2017. 8. 19. 10:14


만들려는 대상



각 버튼과 이미지를 ViewController에 연결

    @IBOutlet weak var labelPage: UILabel!

    @IBOutlet weak var imageView: UIImageView!

    @IBOutlet weak var backOutlet: UIButton!

    @IBOutlet weak var nextOutlet: UIButton!


var imageInt = 0


버튼을 Action으로 연결한 후 이미지 번호를 변경한다.

    @IBAction func buttonNext(_ sender: Any) {

        

        imageInt += 1

        if (imageInt > 3){

            imageInt = 1

        }

        labelPage.text = String("\(imageInt)/3")

        self.imageGallery()

        

    }


    @IBAction func buttonBack(_ sender: Any) {

        imageInt -= 1

        if (imageInt < 1){

            imageInt = 3

        }

        labelPage.text = String("\(imageInt)/3")

        self.imageGallery()

    }



다음으로 이미지 갤러리 펑션을 만든다.

    func imageGallery() {

        

        if imageInt == 1 {

//            backOutlet.isEnabled = false

            imageView.image = UIImage(named: "1swi3Qy.png")

        }

        if imageInt == 2 {

            backOutlet.isEnabled = true

            nextOutlet.isEnabled = true

            imageView.image = UIImage(named: "tea.jpg")

        }

        if imageInt == 3 {

//            nextOutlet.isEnabled = false

            imageView.image = UIImage(named:"tea2.jpg")

        }

        

    }


//주석 처리한 부분은 버튼이 맨 앞으로 가면 안눌러지게 하는 소스이나, 버튼 액션에서 순환하도록 했기 때문에 주석 처리함.

반응형