10장 탭 바 컨트롤러 이용해 여러 개의 뷰 넣기
//
// ViewController.swift
// Tab
//
// Created by stayfoolish on 18/10/2018.
// Copyright © 2018 stayfoolish. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func btnMoveImageView(_ sender: UIButton) {
tabBarController?.selectedIndex = 1
}
@IBAction func btnMoveDatePickerView(_ sender: UIButton) {
tabBarController?.selectedIndex = 2
}
}
//
// ViewController.swift
// ImageView
//
// Created by stayfoolish on 16/10/2018.
// Copyright © 2018 stayfoolish. All rights reserved.
//
import UIKit
class ImageViewController: 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: "lamp_on.png")
imgOff = UIImage(named: "lamp_off.png")
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 { // flase
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
}
}
}
//
// ViewController.swift
// DatePicker
//
// Created by stayfoolish on 16/10/2018.
// Copyright © 2018 stayfoolish. All rights reserved.
//
import UIKit
class DateViewController: UIViewController {
let timeSelector: Selector = #selector(DateViewController.updateTime)
let interval = 1.0
var count = 0
@IBOutlet var lblCurrentTime: UILabel!
@IBOutlet var lblPickerTime: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
Timer.scheduledTimer(timeInterval: interval, target: self, selector: timeSelector, userInfo: nil, repeats: true)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func changeDatePicker(_ sender: UIDatePicker) {
let datePickerview = sender
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss EEE"
lblPickerTime.text = "선택시간: " + formatter.string(from: datePickerview.date)
}
@objc func updateTime() {
// lblCurrentTime.text = String(count)
// count = count + 1
let date = NSDate()
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss EEE"
lblCurrentTime.text = "현재시간: " + formatter.string(from: date as Date)
}
@IBAction func btnMoveFirst(_ sender: UIButton) {
tabBarController?.selectedIndex = 0
}
}
11장 내비게이션 컨트롤러 이용해 화면 전환하기
//
// ViewController.swift
// Navigation
//
// Created by stayfoolish on 18/10/2018.
// Copyright © 2018 stayfoolish. All rights reserved.
//
import UIKit
class ViewController: UIViewController,EditDelegate {
let imgOn = UIImage(named: "lamp_on.png")
let imgOff = UIImage(named: "lamp_off.png")
var isOn = true
@IBOutlet var txMessage: UITextField!
@IBOutlet var imgView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
imgView.image = imgOn
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let editViewController = segue.destination as! EditViewController
if segue.identifier == "editButton" {
editViewController.textWayValue = "segue : use button"
}else if segue.identifier == "editBarButton" {
editViewController.textWayValue = "segue: use Bar button"
}
editViewController.textMessage = txMessage.text!
editViewController.isOn = isOn
editViewController.delegate = self
}
func didMessageEditDone(_ controller: EditViewController, message: String) {
txMessage.text = message
}
func didImageOnOffDone(_ controller: EditViewController, isOn: Bool){
if isOn {
imgView.image = imgOn
self.isOn = true
}else {
imgView.image = imgOff
self.isOn = false
}
}
}
//
// EditViewController.swift
// Navigation
//
// Created by stayfoolish on 18/10/2018.
// Copyright © 2018 stayfoolish. All rights reserved.
//
import UIKit
protocol EditDelegate {
func didMessageEditDone(_ controller: EditViewController, message: String)
func didImageOnOffDone(_ controller: EditViewController, isOn: Bool)
}
class EditViewController: UIViewController {
var textWayValue: String = ""
var textMessage: String = ""
var delegate: EditDelegate?
var isOn = false
@IBOutlet var lblWay: UILabel!
@IBOutlet var txMessage: UITextField!
@IBOutlet var swIson: UISwitch!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
lblWay.text = textWayValue
txMessage.text = textMessage
swIson.isOn = isOn
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func btnDone(_ sender: UIButton) {
if delegate != nil {
delegate?.didMessageEditDone(self, message: txMessage.text!)
delegate?.didImageOnOffDone(self, isOn: isOn)
}
_ = navigationController?.popViewController(animated: true)
}
@IBAction func swImageOnOff(_ sender: UISwitch) {
if sender.isOn {
isOn = true
}else {
isOn = false
}
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
'Swift > 기초&문법' 카테고리의 다른 글
do it 스위프트 아이폰 앱 만들기 13~14장 swift Audio MoviePlayer app 오디오 비디오 앱 (0) | 2018.10.21 |
---|---|
do it 스위프트 아이폰 앱 만들기 12장 swift tableview 테이블뷰 (0) | 2018.10.20 |
do it 스위프트 아이폰 앱 만들기 07~09장 swift webview, mapview, page control (0) | 2018.10.18 |
do it 스위프트 아이폰 앱 만들기 04~06장 swift datepicker, pickerview, alert (0) | 2018.10.17 |
do it 스위프트 아이폰 앱 만들기 01~03장 swift imageview (0) | 2018.10.16 |