Skip to content

Commit

Permalink
[Feat] ButtonBuilder패턴 생성 (+도무지 빌더패턴 왜쓰는지 모르겠음) #8
Browse files Browse the repository at this point in the history
  • Loading branch information
meltsplit committed Apr 22, 2023
1 parent 5ed4d12 commit 99b9d7a
Show file tree
Hide file tree
Showing 10 changed files with 187 additions and 24 deletions.
2 changes: 1 addition & 1 deletion SOPTving/SOPTving/Application/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {

guard let windowScene = (scene as? UIWindowScene) else { return }
window = UIWindow(windowScene: windowScene)
window?.rootViewController = OnboardingVC()
window?.rootViewController = MainVC()
window?.makeKeyAndVisible()
}

Expand Down
48 changes: 28 additions & 20 deletions SOPTving/SOPTving/Presentation/MainScene/VC/MainVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit
import SnapKit
import Then

class MainVC: UIViewController {
final class MainVC: UIViewController {

//MARK: - Properties

Expand All @@ -22,26 +22,30 @@ class MainVC: UIViewController {

//MARK: - UI Components

private let profileImageView: UIImageView = {
let imageView = UIImageView()
imageView.image = UIImage(named: "profile_tving.cute")
imageView.contentMode = .scaleAspectFit
return imageView
}()

private let profileLabel: UILabel = {
let label = UILabel()
label.font = .tvingSemiBold(ofSize: 20)
label.text = "gd"
label.textColor = .white
return label
}()

private lazy var nextButton = ButtonBuilder()
.setTitle("다음으로",
color: .white,
font: .tvingSemiBold(ofSize: 16))
.setBackGroundColor(.systemBlue)
.setCornerRadius(12)
.setAction { [weak self] _ in
self?.nextButtonDidTap()
}
.build()

//MARK: - Life Cycle

override func viewDidLoad() {
super.viewDidLoad()

binding()
style()
hierarchy()
layout()
Expand All @@ -53,10 +57,6 @@ class MainVC: UIViewController {

extension MainVC {

private func binding() {

}

private func updateUI() {
profileLabel.text = name
}
Expand All @@ -69,6 +69,14 @@ extension MainVC {

}

//MARK: - Action Method

extension MainVC {
func nextButtonDidTap() {

}
}




Expand All @@ -82,19 +90,19 @@ extension MainVC {
}

private func hierarchy() {
view.addSubviews(profileImageView,
profileLabel)
view.addSubviews(profileLabel, nextButton)
}

private func layout() {
profileImageView.snp.makeConstraints {
profileLabel.snp.makeConstraints {
$0.center.equalToSuperview()
$0.size.equalTo(80)
}

profileLabel.snp.makeConstraints {
$0.top.equalTo(profileImageView.snp.bottom).offset(20)
$0.centerX.equalTo(profileImageView)
nextButton.snp.makeConstraints {
$0.centerX.equalToSuperview()
$0.top.equalTo(profileLabel.snp.bottom).offset(100)
$0.height.equalTo(40)
$0.width.equalTo(80)
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"images" : [
{
"filename" : "스크린샷_2023-04-13_오전_3.57.44-removebg-preview.png",
"filename" : "스크린샷_2023-04-13_오전_3.57.44-removebg-preview 3.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "스크린샷_2023-04-13_오전_3.57.44-removebg-preview 1.png",
"filename" : "스크린샷_2023-04-13_오전_3.57.44-removebg-preview 4.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "스크린샷_2023-04-13_오전_3.57.44-removebg-preview 2.png",
"filename" : "스크린샷_2023-04-13_오전_3.57.44-removebg-preview.png",
"idiom" : "universal",
"scale" : "3x"
}
Expand Down
87 changes: 87 additions & 0 deletions SOPTving/SOPTving/Utility/Builder/ButtonBuilder.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
//
// ButtonBuilder.swift
// SOPTving
//
// Created by 장석우 on 2023/04/22.
//

import UIKit

protocol ButtonBuildable: ViewBuildable {

func setTitle(_ text: String,
color: UIColor,
font: UIFont,
state: UIControl.State ) -> Self

func setImage(_ image: UIImage,
contentMode: UIView.ContentMode,
state: UIControl.State) -> Self

func setAction(event: UIControl.Event,
handler: @escaping UIActionHandler) -> Self
}

//MARK: - Builder

final class ButtonBuilder: ButtonBuildable {

//MARK: UI Components
private var button = UIButton()

//MARK: Life Cycle

func build() -> UIButton {
return button
}

//MARK: Custom Method

@discardableResult
func setBackGroundColor(_ color: UIColor) -> Self {
button.backgroundColor = color
return self
}

@discardableResult
func setCornerRadius(_ radius: CGFloat) -> Self {
button.makeCornerRound(radius: radius)
return self
}

@discardableResult
func setTitle(_ text: String,
color: UIColor,
font: UIFont ,
state: UIControl.State = .normal) -> Self {
button.setTitle(text, for: state)
button.setTitleColor(color, for: state)
button.titleLabel?.font = font
return self
}

@discardableResult
func setImage(_ image: UIImage,
contentMode: UIView.ContentMode = .scaleAspectFit,
state: UIControl.State = .normal) -> Self {
button.setImage(image, for: state)
button.contentMode = contentMode
return self
}

@discardableResult
func setAction(event: UIControl.Event = .touchUpInside,
handler: @escaping UIActionHandler) -> Self {
let action = UIAction(handler: handler)
button.addAction(action, for: event)
return self
}

}


//MARK: - Director


//MARK: - AuthTextField

52 changes: 52 additions & 0 deletions SOPTving/SOPTving/Utility/Builder/ViewBuilder.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// UIViewBuilder.swift
// SOPTving
//
// Created by 장석우 on 2023/04/22.
//

import UIKit

protocol ViewBuildable {
func setBackGroundColor(_ color: UIColor) -> Self
func setCornerRadius(_ radius: CGFloat) -> Self
}

//MARK: - Builder

class ViewBuilder: ViewBuildable {

//MARK: UI Components
var view = UIView()

//MARK: Life Cycle

init() {
print("뷰빌더 init")
}

func build() -> UIView {
return view
}

//MARK: Custom Method

@discardableResult
func setBackGroundColor(_ color: UIColor) -> Self {
view.backgroundColor = color
return self
}

@discardableResult
func setCornerRadius(_ radius: CGFloat) -> Self {
view.makeCornerRound(radius: radius)
return self
}
}


//MARK: - Director


//MARK: - AuthTextField

8 changes: 8 additions & 0 deletions SOPTving/SOPTving/Utility/DataStructure/LinkedList.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// LinkedList.swift
// SOPTving
//
// Created by 장석우 on 2023/04/22.
//

import Foundation
8 changes: 8 additions & 0 deletions SOPTving/SOPTving/Utility/DataStructure/Node.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// Node.swift
// SOPTving
//
// Created by 장석우 on 2023/04/22.
//

import Foundation

0 comments on commit 99b9d7a

Please sign in to comment.