To Practice UINavigationController, transition, ViewController Life Cycle, send data to different page, asset catalogs

Overview

LED Board

Kapture 2021-11-25 at 18 15 10

Check Point !

StackView

  • 여러개의 view 를 set 으로 만들어 주는 역활을 함

  • 일정한 규칙에 따라서 stack view 안에 움직이는것임

이미지 넣기

  • 프로젝트 내에 Assets 폴더 내에 Image Set 을 추가하여 1x, 2x, 3x 의 크기의 맞게 해당 이미지를 넣어 줍니다 (24px, 48px, 72px 사이즈의 이미지를 추가함) -> 다양한 크기의 image 를 추가하는것은 iphone, ipad 등 다양한 해상도에서 이미지가 깨지지 않게 하기 위함임

주요 코드

image

// viewController.swift

class ViewController: UIViewController, LEDBoardSettingDelegate {
	@IBOutlet weak var contentsLabel: UILabel!

	override func viewDidLoad() {
		super.viewDidLoad()
		self.contentsLabel.textColor = .yellow
	}

	// delegate 된 data 받기(segueway 를 통해서)
	override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
		if let settingViewController = segue.destination as? SettingViewController {
			settingViewController.delegate = self

			// setting 페이지에 다시 값 넘겨 주기
			settingViewController.ledText = self.contentsLabel.text
			settingViewController.textColor = self.contentsLabel.textColor
			settingViewController.backgroundColor = self.view.backgroundColor ?? .black // optional 값이면 .black 으로 설정
		}
	}

	// setting 에서 받은 data 로 view 에 초기화 하기
	func changedSetting(text: String?, textColor: UIColor, backgroundColor: UIColor) {
		if let text = text {
			self.contentsLabel.text = text
		}
		self.contentsLabel.textColor = textColor
		self.view.backgroundColor = backgroundColor
	}
}
// settingViewController.swift

// delegate pattern : 이전화면에서 설정된 값들을 앞 페이지로 전달하기
protocol LEDBoardSettingDelegate: AnyObject {
	func changedSetting(text: String?, textColor: UIColor, backgroundColor: UIColor)
}

class SettingViewController: UIViewController {

	// TextFiled 연결
	@IBOutlet weak var textField: UITextField!

	// Text Colors 연결
	@IBOutlet weak var yellowBtn: UIButton!
	@IBOutlet weak var purpleBtn: UIButton!
	@IBOutlet weak var greenBtn: UIButton!

	// Background Colors 연결
	@IBOutlet weak var blackBtn: UIButton!
	@IBOutlet weak var blueBtn: UIButton!
	@IBOutlet weak var orangeBtn: UIButton!

	// delegate 변수
	weak var delegate: LEDBoardSettingDelegate?

	// 저장되고 앞에서 다시 설정할때 앞페이지에서 값을 받을 수 있게 변수 설정
	var ledText: String?

	// 초기화 값 설정
	var textColor: UIColor = .yellow
	var backgroundColor: UIColor = .black

	override func viewDidLoad() {
		super.viewDidLoad()
		// led 화면에서 받은값이 페이지 로드 될때 불러오기
		self.configureView()
	}

	// 앞에서 전달 받은 데이터들로 view 를 초기화 하기
	private func configureView() {
		if let ledText = self.ledText {
			self.textField.text = ledText
		}
		self.changeTextColor(color: self.textColor)
		self.changeBackgroundColor(color: self.backgroundColor)
	}

	@IBAction func tabTextColorBtn(_ sender: UIButton) {
		if sender == self.yellowBtn {
			self.changeTextColor(color: .yellow)
			self.textColor = .yellow
		} else if sender == self.purpleBtn {
			self.changeTextColor(color: .purple)
			self.textColor = .purple
		} else {
			self.changeTextColor(color: .green)
			self.textColor = .green
		}
	}

	@IBAction func tabBackgroundColorBtn(_ sender: UIButton) {
		if sender == self.blackBtn {
			self.changeBackgroundColor(color: .black)
			self.backgroundColor = .black
		} else if sender == self.blueBtn {
			self.changeBackgroundColor(color: .blue)
			self.backgroundColor = .blue
		} else {
			self.changeBackgroundColor(color: .orange)
			self.backgroundColor = .orange
		}
	}

	// 설정 된 delegate 값을 Save 버튼 누르면 보내는 logic
	@IBAction func tabSaveButton(_ sender: UIButton) {
		self.delegate?.changedSetting(
			text: self.textField.text,
			textColor: self.textColor,
			backgroundColor: self.backgroundColor
		)
		// 이전화면으로 이동
		self.navigationController?.popViewController(animated: true)
	}

	// 선택된 color는 alpha 값을 1로 하고 선택되지 않은 color 는 alpha 를 0.2로 설정
	private func changeTextColor(color: UIColor) {
		self.yellowBtn.alpha = color == UIColor.yellow ? 1 : 0.2
		self.purpleBtn.alpha = color == UIColor.purple ? 1 : 0.2
		self.greenBtn.alpha = color == UIColor.green ? 1 : 0.2
	}
	private func changeBackgroundColor(color: UIColor) {
		self.blackBtn.alpha = color == UIColor.black ? 1 : 0.2
		self.blueBtn.alpha = color == UIColor.blue ? 1 : 0.2
		self.orangeBtn.alpha = color == UIColor.orange ? 1 : 0.2
	}
}

reference

Jacob's DevLog - https://jacobko.info/ios/ios-03/

On the swift - https://ontheswift.tistory.com/8

농부와 코드 - https://tono18.tistory.com/11

fastcampus - https://fastcampus.co.kr/dev_online_iosappfinal

You might also like...
This to learn such as : Add Target , NSNotification Center Send/Get Data , Observer Override , resize Data By Byte , UIImagePicker Delegate , UIAlert Handle , Top ViewController , Get pickerController

Technicalisto How to Create UIButton Class to Pick Data Image Purpose Learn this topics With exact Task Add Target NSNotification Center Send/Get Data

Reading animation allows you to click on the different page numbers and accordingly it will animate page changes in a cool way. It has a very attractive UI and is very easy to use.
Reading animation allows you to click on the different page numbers and accordingly it will animate page changes in a cool way. It has a very attractive UI and is very easy to use.

Reading Animation Cool Reading Animation in iOS written in Swift. Preview Table of content :- Description How to add in your project Requirement Licen

Enables easy, convenient asynchronous asset loading in RealityKit for many different kinds of assets.

RealityKit Asset Loading Discussion This package includes classes and examples that enable easy, convenient asynchronous asset loading in RealityKit f

Automatically build and rebuild Xcode image catalogs for app icons, universal images, and more
Automatically build and rebuild Xcode image catalogs for app icons, universal images, and more

Better asset workflow for iOS developers. Generate Xcode image catalogs for iOS / OSX app icons, universal images, and more.

SwiftUI implementation of Conway’s Game of Life — also known as “Life”.
SwiftUI implementation of Conway’s Game of Life — also known as “Life”.

Life Conway’s Game of Life SwiftUI implementation of Conway’s Game of Life — also known simply as “Life”. About I’m Martin, an indie dev from Berlin.

Present a sheet ViewController easily and control ViewController height with pangesture
Present a sheet ViewController easily and control ViewController height with pangesture

PanControllerHeight is designed to present a sheet ViewController easily and control ViewController height with pangesture.

GroceryMartApp-iOS-practice - To Practice fundamental SwiftUI feature like navigation, state mamagement, customazing etc
GroceryMartApp-iOS-practice - To Practice fundamental SwiftUI feature like navigation, state mamagement, customazing etc

🥬 GroceryMartApp-iOS-practice 아래의 내용은 스윗한 SwiftUI 책의 실전 앱 구현하기 을 바탕으로 정리한 내용입니다

FruitsDic-ios-practice - To Practice onboarding , List, detail and setting View
FruitsDic-ios-practice - To Practice onboarding , List, detail and setting View

🍓 FruitsDic-ios-practice 📌 기능 상세 OnBoding Screen with Page Tab View Data model

JSON-Practice - JSON Practice With Swift

JSON Practice Vista creada con: Programmatic + AutoLayout Breve explicación de l

Controls-Practice-UIKit- - Controls Practice (UIKit)
Controls-Practice-UIKit- - Controls Practice (UIKit)

Controls Practice (UIKit) Change a number 0 to 255 different ways: Button (+1) I

ProductPage - An example project that shows how to build a product page in a modular way. SwiftUI practice

ProductPage An example project that shows how to build a product page in a modul

A PageView Swiping to the left will go to previous page and swiping to the right will go to next page
A PageView Swiping to the left will go to previous page and swiping to the right will go to next page

PageView This package creates a PageView. Swiping to the left will go to previous page and swiping to the right will go to next page. You can find how

Transition animation for ViewController

XTransitionKit Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements iOS 9.0+ Swift 5

LifetimeTracker can surface retain cycle / memory issues right as you develop your application
LifetimeTracker can surface retain cycle / memory issues right as you develop your application

LifetimeTracker Bar style Circular style LifetimeTracker can surface retain cycle / memory issues right as you develop your application, and it will s

CycleTrainerApp - Cycle Trainer App With Swift

CycleTrainerApp Bike computer app that records your ride and shows you metrics f

Android/iOS Apps created to practice with different iOS/Android Tech. These apps were built to have similar feature sets using native Android/iOS.

AgilityFitTodayApp Android/iOS Apps created to practice with different iOS/Android Tech. These apps were built to have similar feature sets using nati

Custom-Transition - A repo about custom transition between two view controllers

Custom-Transition in SWIFT This is a repo about custom transition between two vi

Appstore card animation transition. UICollectionView and UITableView card expand animated transition
Appstore card animation transition. UICollectionView and UITableView card expand animated transition

Appstore card animation transition. UICollectionView and UITableView card expand animated transition. This library tries to add the appstore transition to your own app. The goal is to be as simple as possible to integrate in an app while keeping the flexibility and customization alive.

A drop-in universal library helps you to manage the navigation bar styles and makes transition animations smooth between different navigation bar styles
A drop-in universal library helps you to manage the navigation bar styles and makes transition animations smooth between different navigation bar styles

A drop-in universal library helps you to manage the navigation bar styles and makes transition animations smooth between different navigation bar styles while pushing or popping a view controller for all orientations. And you don't need to write any line of code for it, it all happens automatically.

Owner
Jacob Ko
Everything is Awesome
Jacob Ko
Send key events to any running macOS application.

KeySender An extremely simple micro package that enables you to send key events to any running application. Install Add the following to your Package.

Jordan Baird 5 Jul 31, 2022
Send email to any SMTP server like a boss, in Swift and cross-platform

Hedwig is a Swift package which supplies a set of high level APIs to allow you sending email to an SMTP server easily. If you are planning to send ema

Wei Wang 1.1k Jan 3, 2023
TouchID used easy on one line in your ViewController.

TouchIDExtension TouchID used easy on one line in your ViewController. ##Installation At this moment, You can install only a way, manually. For instal

Joan Molinas 65 Feb 26, 2020
Demotivator: A simple app for practice

Demotivator This is a simple app for practice. Programmatically Quick recap: .Ph

Dmitry Yatsyuk 0 Dec 17, 2021
Easy to use cryptographic framework for data protection: secure messaging with forward secrecy and secure data storage. Has unified APIs across 14 platforms.

Themis provides strong, usable cryptography for busy people General purpose cryptographic library for storage and messaging for iOS (Swift, Obj-C), An

Cossack Labs 1.6k Dec 30, 2022
Valet lets you securely store data in the iOS, tvOS, or macOS Keychain without knowing a thing about how the Keychain works.

Valet Valet lets you securely store data in the iOS, tvOS, watchOS, or macOS Keychain without knowing a thing about how the Keychain works. It’s easy.

Square 3.8k Jan 4, 2023
Simple, secure password and data management for individuals and teams

Padloc Simple, secure password and data management for individuals and teams (formerly known as Padlock). This repo is split into multiple packages: P

Padloc 2.1k Jan 8, 2023
Conflict-free Replicated Data Types in Swift

CRDT An implementation of ∂-state based Conflict-free Replicated Data Types (CRDT) in the Swift language. Overview This library implements well-known

Joseph Heck 29 Dec 8, 2022
SwiftUI - iOS notes App that integrates Core Data with SwiftUI App Life Cycle

Devote (Notes App) SwiftUI Masterclass project Integration between Core Data and SwiftUI App Life Cycle Custom Toggle style and checkbox Read, Update

Arthur Neves 3 Sep 3, 2022
Asset Catalog Viewer allows you to browse and export renditions in an asset catalog (.car) file.

Asset Catalog Viewer With the Asset Catalog Viewer Mac app, you can browse and export various type of renditions in an asset catalog. Features Browse

Joey 16 Jan 1, 2023