class ViewController: UIViewController {

    @IBOutlet weak var imgMain: UIImageView!

    @IBOutlet weak var btnPrev: UIButton!

    @IBOutlet weak var btnNext: UIButton!

    var idx = 0

    

    var array_img = ["img1.jpeg" , "img2.jpeg" , "img3.jpeg"]


    override func viewDidLoad() {

        super.viewDidLoad()

        // Do any additional setup after loading the view, typically from a nib.

        initView(_pos : 0);

    }

    

    func initView(_pos : Int){

        print( "current pos -> \(_pos)" )

        imgMain.image = UIImage(named: array_img[_pos]);

    }


    override func didReceiveMemoryWarning() {

        super.didReceiveMemoryWarning()

        // Dispose of any resources that can be recreated.

    }


    @IBAction func showPrevPrc(_ sender: Any) {

        idx -= 1

        if ( idx < 0 ){

         idx = array_img.count - 1

        }

        

        

        initView(_pos: idx);

    }

    

    @IBAction func showNextPrc(_ sender: Any) {

        idx += 1

        if(idx >= array_img.count){

            idx = 0;

        }

        

        initView(_pos: idx);

        

    }

    


}

+ Recent posts