-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Chore] #254 - chip builder implemented & director method implemented
- Loading branch information
1 parent
7c7ee4d
commit 01b1cce
Showing
3 changed files
with
137 additions
and
0 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
90 changes: 90 additions & 0 deletions
90
GEON-PPANG-iOS/Core/DesignSystem/UIComponents/View/Chip/ChipBuilder.swift
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,90 @@ | ||
// | ||
// ChipBuilder.swift | ||
// GEON-PPANG-iOS | ||
// | ||
// Created by 이성민 on 5/5/24. | ||
// | ||
|
||
import UIKit | ||
import SnapKit | ||
|
||
internal protocol Builder { | ||
associatedtype View | ||
func build() -> View | ||
} | ||
|
||
public final class ChipBuilder: Builder { | ||
|
||
private let view: UIView | ||
private let label: UILabel | ||
|
||
init() { | ||
self.view = UIView() | ||
self.label = UILabel() | ||
setLayout() | ||
} | ||
|
||
private func setLayout() { | ||
self.view.addSubview(label) | ||
self.label.snp.makeConstraints { | ||
$0.edges.equalTo(view.snp.edges).inset(0) | ||
} | ||
} | ||
|
||
func build() -> UIView { | ||
return self.view | ||
} | ||
} | ||
|
||
extension ChipBuilder { | ||
public func setText(to text: String) -> ChipBuilder { | ||
self.label.text = text | ||
return self | ||
} | ||
|
||
public func setTextColor(to color: UIColor) -> ChipBuilder { | ||
self.label.textColor = color | ||
return self | ||
} | ||
|
||
public func setTextFont(to font: UIFont) -> ChipBuilder { | ||
self.label.font = font | ||
return self | ||
} | ||
|
||
public func setCornerRadius(to amount: CGFloat) -> ChipBuilder { | ||
self.view.layer.masksToBounds = true | ||
self.view.layer.cornerRadius = amount | ||
return self | ||
} | ||
|
||
public func setBackgroundColor(to color: UIColor) -> ChipBuilder { | ||
self.view.backgroundColor = color | ||
return self | ||
} | ||
|
||
public func setBorderWidth(to width: CGFloat) -> ChipBuilder { | ||
self.view.layer.borderWidth = width | ||
return self | ||
} | ||
|
||
public func setBorderColor(to color: UIColor) -> ChipBuilder { | ||
self.label.layer.borderColor = color.cgColor | ||
return self | ||
} | ||
|
||
public func setPadding( | ||
top: CGFloat, | ||
right: CGFloat, | ||
bottom: CGFloat, | ||
left: CGFloat | ||
) -> ChipBuilder { | ||
self.label.snp.updateConstraints { | ||
$0.top.equalTo(view.snp.top).inset(top) | ||
$0.right.equalTo(view.snp.right).inset(right) | ||
$0.bottom.equalTo(view.snp.bottom).inset(bottom) | ||
$0.left.equalTo(view.snp.left).inset(left) | ||
} | ||
return self | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
GEON-PPANG-iOS/Core/DesignSystem/UIComponents/View/Chip/ChipDirector.swift
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,23 @@ | ||
// | ||
// ChipDirector.swift | ||
// GEON-PPANG-iOS | ||
// | ||
// Created by 이성민 on 5/5/24. | ||
// | ||
|
||
import UIKit | ||
|
||
public final class ChipDirector { | ||
|
||
static func buildPointChip(with text: String) -> UIView { | ||
ChipBuilder() | ||
.setText(to: text) | ||
.setTextFont(to: .captionM1) | ||
.setTextColor(to: .gbbPoint1) | ||
.setCornerRadius(to: 3) | ||
.setBackgroundColor(to: .gbbPoint2) | ||
.setPadding(top: 4, right: 5, bottom: 4, left: 5) | ||
.build() | ||
} | ||
|
||
} |