//

//  ViewController.swift

//  ImageView

//

//  Created by stayfoolish on 2018. 8. 22..

//  Copyright © 2018년 stayfoolish. All rights reserved.

//


import UIKit


class ViewController: UIViewController {

    

    var isZoom = false

    var imgOn: UIImage?

    var imgOff: UIImage?

    

    

    @IBOutlet var imgView: UIImageView!

    @IBOutlet var btnResize: UIButton!

    

    override func viewDidLoad() {

        super.viewDidLoad()

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

        

        imgOn = UIImage(named: "23efa0b90b7c7935d4e63e88ce863c25.jpg")

        imgOff = UIImage(named: "slack1.jpeg" )

        

        imgView.image = imgOn

    }


    override func didReceiveMemoryWarning() {

        super.didReceiveMemoryWarning()

        // Dispose of any resources that can be recreated.

    }


    @IBAction func btnResizeImage(_ sender: UIButton) {

        let scale:CGFloat = 2.0

        var newWidth:CGFloat, newHeight:CGFloat

        

        if (isZoom){ // true

            newWidth = imgView.frame.width/scale

            newHeight = imgView.frame.height/scale

            imgView.frame.size = CGSize(width: newWidth, height: newHeight)

            btnResize.setTitle("확대", for: .normal)

            

        }else {

            newWidth = imgView.frame.width*scale

            newHeight = imgView.frame.height*scale

            imgView.frame.size = CGSize(width: newWidth, height: newHeight)

            btnResize.setTitle("축소", for: .normal)

        }

        isZoom = !isZoom

    }

    

    @IBAction func switchImageOnOff(_ sender: UISwitch) {

        if sender.isOn{

            imgView.image = imgOn

        }else {

            imgView.image = imgOff

        }

    }

}



+ Recent posts