250x250
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- keyframes
- iPhone
- 비전공자
- 프론트엔드
- HTML
- html5
- Animation
- front-end
- hover
- react
- iOS 개발자
- 개발자
- IOS
- effect
- xcode
- CSS
- image
- 애니메이션
- ipad
- MAC
- 풀스택
- css3
- 비전공 개발자
- button
- 백엔드
- SWIFT
- php
- javascript
- jQuery
- 자바스크립트
Archives
- Today
- Total
비전공자 개발일기
Display Background color & Text Setting 본문
728x90
SMALL
import UIKit
class ViewController: UIViewController, displaySettingDelegate {
@IBOutlet weak var contentLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
contentLabel.textColor = UIColor.orange
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let settingViewController = segue.destination as? SettingViewController {
settingViewController.delegate = self
settingViewController.displayText = contentLabel.text
settingViewController.textColor = contentLabel.textColor
settingViewController.backgroundColor = view.backgroundColor ?? .black
}
}
func changeSetting(text: String?, textColor: UIColor, backgroundColor: UIColor) {
if let text = text {
contentLabel.text = text
}
contentLabel.textColor = textColor
view.backgroundColor = backgroundColor
}
}
import UIKit
protocol displaySettingDelegate: AnyObject {
func changeSetting(text: String?, textColor: UIColor, backgroundColor: UIColor)
}
class SettingViewController: UIViewController {
@IBOutlet weak var textField: UITextField!
@IBOutlet weak var blueBTN: UIButton!
@IBOutlet weak var purpleBTN: UIButton!
@IBOutlet weak var blackBTN: UIButton!
@IBOutlet weak var greenBTN: UIButton!
@IBOutlet weak var yellowBTN: UIButton!
@IBOutlet weak var orangeBTN: UIButton!
weak var delegate: displaySettingDelegate?
var displayText: String?
var textColor: UIColor = .orange
var backgroundColor: UIColor = .black
override func viewDidLoad() {
super.viewDidLoad()
makeUI()
}
private func makeUI() {
if let displayText = self.displayText {
textField.text = displayText
}
changeTextClr(color: textColor)
changeBgClr(color: backgroundColor)
}
@IBAction func changeTextColor(_ sender: UIButton) {
if sender == orangeBTN {
changeTextClr(color: .orange)
textColor = .orange
} else if sender == yellowBTN {
changeTextClr(color: .yellow)
textColor = .yellow
} else {
changeTextClr(color: .green)
textColor = .green
}
}
@IBAction func changeBGColor(_ sender: UIButton) {
if sender == blackBTN {
changeBgClr(color: .black)
backgroundColor = .black
} else if sender == purpleBTN {
changeBgClr(color: .purple)
backgroundColor = .purple
} else {
changeBgClr(color: .blue)
backgroundColor = .blue
}
}
@IBAction func saveBTN(_ sender: UIButton) {
delegate?.changeSetting(text: textField.text, textColor: textColor, backgroundColor: backgroundColor)
navigationController?.popViewController(animated: true)
}
private func changeTextClr(color: UIColor) {
orangeBTN.alpha = color == UIColor.orange ? 1 : 0.2
yellowBTN.alpha = color == UIColor.yellow ? 1 : 0.2
greenBTN.alpha = color == UIColor.green ? 1 : 0.2
}
private func changeBgClr(color: UIColor) {
blackBTN.alpha = color == UIColor.black ? 1 : 0.2
purpleBTN.alpha = color == UIColor.purple ? 1 : 0.2
blueBTN.alpha = color == UIColor.blue ? 1 : 0.2
}
}
728x90
LIST
'SWIFT' 카테고리의 다른 글
To Do List (0) | 2022.12.14 |
---|---|
Basic Calculator (0) | 2022.12.13 |
Quote Generator (0) | 2022.12.12 |
Swift Study - Function, Class, Struct, Closure (0) | 2022.12.10 |
BMI Calculator (0) | 2022.12.08 |