01. 아이폰 앱 개발 준비하기
* 아이폰 시장
2016년 4분기 세계 스마트폰 점유율 : 애플 20.3 %
출처 : 트렌드포스(2017년 4월)
* 스위프트의 장점
- 빠르고 강력하다
- 완전한 플랫폼이다.
- 현대적이다.
- 상호 반응적인 플레이그라운드
- 안전을 위한 설계
- 오브젝티브-c와의 상호 운용성
- 오픈 소스이다.
- 스위프트 특징 : https://developer.apple.com/swift
- 스위프트 언어 개발 문서 : http://swift.leantra.kr ( 현재시점 내용이 보이지 않음)
- 직접 알게 된 스위프트 한글 번역 사이트 : https://jusung.gitbook.io/the-swift-language-guide/
*Xcode가 설치된 맥 PC 준비하기
Xcode가 macOs에서만 동작한다.
02. Hello World 앱 만들며 Xcode에 완벽 적응하기
//
// ViewController.swift
// HelloWorld
//
// Created by stayfoolish on 16/10/2018.
// Copyright © 2018 stayfoolish. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
@IBOutlet var lblHello: UILabel!
@IBOutlet var txtName: UITextField!
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 btnSend(_ sender: UIButton) {
lblHello.text = "Hello, " + txtName.text!
}
}
03. 원하는 이미지 화면에 출력하기 - 이미지뷰
//
// ViewController.swift
// ImageView
//
// Created by stayfoolish on 16/10/2018.
// 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: "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
}
}
}
'Swift > 기초&문법' 카테고리의 다른 글
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 |
swift struct class 스위프트 구조체 클래스 value type reference type (0) | 2018.10.13 |
스위프트 할일 앱 노티피케이션 swift Todos nofitication (0) | 2018.10.12 |
스위프트 함수 스코프 swift function return scope (0) | 2018.10.11 |