Skip to content

Commit

Permalink
#171: Tag 컴포넌트 추가 > 사이즈별 관리 예정, Purple/Yellow 케이스 존재
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-muuu committed Feb 11, 2023
1 parent 23184b5 commit ce4c5e9
Show file tree
Hide file tree
Showing 3 changed files with 185 additions and 1 deletion.
101 changes: 101 additions & 0 deletions Zatch/Global/Source/Component/Tag/Tag.swift
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
}
}
}
83 changes: 83 additions & 0 deletions Zatch/Global/Source/Component/Tag/TagStlye.swift
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
}
}
}
2 changes: 1 addition & 1 deletion Zatch/Global/Source/Component/ZatchComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
import Foundation

class ZatchComponent{

}

0 comments on commit ce4c5e9

Please sign in to comment.