利用if、else if、else製作拍立得App_Week07
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var mickyImageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBAction func ratioValueChange(_ sender: UISegmentedControl) {
let width:CGFloat=250
var height:CGFloat=0
if sender.selectedSegmentIndex==0{height=width}
else if sender.selectedSegmentIndex==1{height=width/3*4}
else {height=width/9*16}
mickyImageView.frame=CGRect(x: 83, y: 118, width: width, height: height)
}
@IBAction func ratioButtomTapped(_ sender: UIButton) {
let width: CGFloat=250
var height:CGFloat=0
if sender.currentTitle==”1:1"{sender.setTitle(“3:4”, for: UIControl.State.normal)
height=width/3*4
}
else if sender.currentTitle==”3:4"{sender.setTitle(“16:9”, for: UIControl.State.normal)
height=width/9*16
}
else {sender.setTitle(“1:1”, for: UIControl.State.normal)
height=width
}
mickyImageView.frame=CGRect(x: 83, y: 118, width: width, height: height)
}
}