From ce4c5e9f52e1b6ac9c27f9a2521df133e5bce340 Mon Sep 17 00:00:00 2001 From: SSOOYA Date: Sat, 11 Feb 2023 14:02:44 +0900 Subject: [PATCH] =?UTF-8?q?#171:=20Tag=20=EC=BB=B4=ED=8F=AC=EB=84=8C?= =?UTF-8?q?=ED=8A=B8=20=EC=B6=94=EA=B0=80=20>=20=EC=82=AC=EC=9D=B4?= =?UTF-8?q?=EC=A6=88=EB=B3=84=20=EA=B4=80=EB=A6=AC=20=EC=98=88=EC=A0=95,?= =?UTF-8?q?=20Purple/Yellow=20=EC=BC=80=EC=9D=B4=EC=8A=A4=20=EC=A1=B4?= =?UTF-8?q?=EC=9E=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Zatch/Global/Source/Component/Tag/Tag.swift | 101 ++++++++++++++++++ .../Source/Component/Tag/TagStlye.swift | 83 ++++++++++++++ .../Source/Component/ZatchComponent.swift | 2 +- 3 files changed, 185 insertions(+), 1 deletion(-) create mode 100644 Zatch/Global/Source/Component/Tag/Tag.swift create mode 100644 Zatch/Global/Source/Component/Tag/TagStlye.swift diff --git a/Zatch/Global/Source/Component/Tag/Tag.swift b/Zatch/Global/Source/Component/Tag/Tag.swift new file mode 100644 index 00000000..f3b7b6b3 --- /dev/null +++ b/Zatch/Global/Source/Component/Tag/Tag.swift @@ -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 + } + } +} diff --git a/Zatch/Global/Source/Component/Tag/TagStlye.swift b/Zatch/Global/Source/Component/Tag/TagStlye.swift new file mode 100644 index 00000000..28f5fd59 --- /dev/null +++ b/Zatch/Global/Source/Component/Tag/TagStlye.swift @@ -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 + } + } +} diff --git a/Zatch/Global/Source/Component/ZatchComponent.swift b/Zatch/Global/Source/Component/ZatchComponent.swift index 95564174..9af28695 100644 --- a/Zatch/Global/Source/Component/ZatchComponent.swift +++ b/Zatch/Global/Source/Component/ZatchComponent.swift @@ -8,5 +8,5 @@ import Foundation class ZatchComponent{ - + }