generated from GO-SOPT-iOS-Part/KimSeungChan
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feat] ButtonBuilder패턴 생성 (+도무지 빌더패턴 왜쓰는지 모르겠음) #8
- Loading branch information
Showing
10 changed files
with
187 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
SOPTving/SOPTving/Resource/Assets.xcassets/profile_tving.cute.imageset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |