-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#171: Tag 컴포넌트 추가 > 사이즈별 관리 예정, Purple/Yellow 케이스 존재
- Loading branch information
Showing
3 changed files
with
185 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// | ||
// Tag.swift | ||
// Zatch | ||
// | ||
// Created by 박소윤 on 2023/02/11. | ||
// | ||
|
||
import Foundation | ||
|
||
extension ZatchComponent{ | ||
|
||
class PurlpleTag: Tag{ | ||
|
||
init(configuration: ZatchComponent.Tag.TagType){ | ||
super.init(color: .purple, configuration: configuration) | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
} | ||
|
||
class YellowTag: Tag{ | ||
|
||
init(configuration: ZatchComponent.Tag.TagType){ | ||
super.init(color: .purple, configuration: configuration) | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
} | ||
|
||
class Tag: UILabel{ | ||
|
||
var isSelected = false{ | ||
didSet{ | ||
isSelected ? setSelectState() : setNormalState() | ||
} | ||
} | ||
|
||
private let configuration: TagType | ||
private let colorType: TagColor | ||
|
||
init(color: TagColor, configuration: TagType){ | ||
self.colorType = color | ||
self.configuration = configuration | ||
super.init(frame: .zero) | ||
initialize() | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
override func drawText(in rect: CGRect) { | ||
let inset = configuration.padding.inset | ||
super.drawText(in: rect.inset(by: inset)) | ||
} | ||
|
||
override var intrinsicContentSize: CGSize{ | ||
let padding = configuration.padding | ||
var contentSize = super.intrinsicContentSize | ||
contentSize.height += padding.top + padding.bottom | ||
contentSize.width += padding.left + padding.right | ||
return contentSize | ||
} | ||
|
||
private func initialize(){ | ||
style() | ||
layout() | ||
setNormalState() | ||
} | ||
|
||
private func style(){ | ||
self.layer.cornerRadius = configuration.height / 2 | ||
self.clipsToBounds = true | ||
self.setTypoStyleWithSingleLine(typoStyle: configuration.font) | ||
} | ||
|
||
private func layout(){ | ||
self.snp.makeConstraints{ | ||
$0.height.equalTo(configuration.height) | ||
} | ||
} | ||
|
||
private func setNormalState(){ | ||
self.textColor = colorType.textColor | ||
self.backgroundColor = colorType.backgroundColor | ||
} | ||
|
||
private func setSelectState(){ | ||
self.textColor = colorType.selectedTextColor | ||
self.backgroundColor = colorType.selectedBackgroundColor | ||
} | ||
|
||
func setTitle(_ title: String){ | ||
self.text = title | ||
} | ||
} | ||
} |
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,83 @@ | ||
// | ||
// TagStlye.swift | ||
// Zatch | ||
// | ||
// Created by 박소윤 on 2023/02/11. | ||
// | ||
|
||
import Foundation | ||
|
||
extension ZatchComponent.Tag{ | ||
|
||
enum TagColor{ | ||
case purple | ||
case yellow | ||
} | ||
|
||
enum TagType{ | ||
case height20 | ||
} | ||
} | ||
|
||
extension ZatchComponent.Tag.TagColor{ | ||
|
||
struct TagColorStyle{ | ||
let textColor: UIColor | ||
let backgroundColor: UIColor | ||
let selectedTextColor: UIColor = .white | ||
let selectedBackgroundColor: UIColor | ||
} | ||
|
||
private var colorInfo: TagColorStyle{ | ||
switch self{ | ||
case .purple: | ||
return TagColorStyle(textColor: .zatchPurple, | ||
backgroundColor: .purple40, | ||
selectedBackgroundColor: .zatchPurple) | ||
case .yellow: | ||
return TagColorStyle(textColor: .zatchDeepYellow, | ||
backgroundColor: .yellow40, | ||
selectedBackgroundColor: .zatchDeepYellow) | ||
} | ||
} | ||
|
||
var textColor: UIColor{ | ||
colorInfo.textColor | ||
} | ||
|
||
var backgroundColor: UIColor{ | ||
colorInfo.backgroundColor | ||
} | ||
|
||
var selectedTextColor: UIColor{ | ||
colorInfo.selectedTextColor | ||
} | ||
|
||
var selectedBackgroundColor: UIColor{ | ||
colorInfo.selectedBackgroundColor | ||
} | ||
} | ||
|
||
extension ZatchComponent.Tag.TagType{ | ||
|
||
var padding: ZatchComponent.Padding{ | ||
switch self{ | ||
case .height20: return ZatchComponent.Padding(left: 8, right: 8, top: 0, bottom: 0) | ||
default: return ZatchComponent.Padding(left: 0, right: 0, top: 0, bottom: 0) | ||
} | ||
} | ||
|
||
var font: TypoStyle{ | ||
switch self{ | ||
case .height20: return .medium12 | ||
default: return .medium12 | ||
} | ||
} | ||
|
||
var height: CGFloat{ | ||
switch self{ | ||
case .height20: return 20 | ||
default: return 20 | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -8,5 +8,5 @@ | |
import Foundation | ||
|
||
class ZatchComponent{ | ||
|
||
} |