//
// 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
}
}
}
'Swift > 기초&문법' 카테고리의 다른 글
스위프트 swift 피커뷰 원하는 이미지 선택 (0) | 2018.08.24 |
---|---|
스위프트 swift 데이트 피커 사용해 날짜 선택하는 앱 (0) | 2018.08.24 |
스위프트 swift 열거형 enum (0) | 2018.08.21 |
스위프트 swift 클래스 class (0) | 2018.08.21 |
스위프트 swift 구조체 (0) | 2018.08.20 |