Skip to content

Commit

Permalink
[#12] TabComponent 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
chongin12 committed Feb 1, 2025
1 parent a44d6d2 commit c15f4d5
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 1 deletion.
122 changes: 122 additions & 0 deletions Handy/Handy-Storybook/Atom/TabsViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
//
// TabsViewController.swift
// Handy
//
// Created by chongin on 12/29/24.
//

import Handy

final class TabsViewController: BaseViewController {
private let tab1: HandyTabComponent = {
let tabComponent = HandyTabComponent(size: .small)
tabComponent.backgroundColor = .gray100
tabComponent.title = "tabbbbb"
return tabComponent
}()

private let tab2: HandyTabComponent = {
let tabComponent = HandyTabComponent(size: .large)
tabComponent.backgroundColor = .gray100
tabComponent.title = "tabbbbb"
tabComponent.isSelected = true
return tabComponent
}()

override func setViewHierarchies() {
self.view.addSubview(tab1)
self.view.addSubview(tab2)
}

override func setViewLayouts() {
tab1.snp.makeConstraints {
$0.top.leading.equalToSuperview().inset(100)
}

tab2.snp.makeConstraints {
$0.top.leading.equalToSuperview().inset(200)
}
}
}


import UIKit

open class HandyTabComponent: UIControl {
public var size: SizeType = .large

private let titleLabel = HandyLabel(style: .B1Sb16)
private let activeIndicatorBar = UIView()

public var title: String? {
didSet {
setTitleLabel()
}
}

public override var isSelected: Bool {
didSet {
setConfiguration()
}
}

public init(size: SizeType) {
super.init(frame: .zero)
self.size = size
initializeViewHierarchy()
initializeConstraints()
setConfiguration()
}

required public init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

private func initializeViewHierarchy() {
// Set View Hierarchy
self.addSubview(titleLabel)
self.addSubview(activeIndicatorBar)
}

private func initializeConstraints() {
// Set Constraints
titleLabel.snp.makeConstraints {
$0.leading.trailing.equalToSuperview().inset(16)
$0.top.bottom.equalToSuperview().inset(12)
}

activeIndicatorBar.snp.makeConstraints {
$0.bottom.equalToSuperview()
$0.leading.trailing.equalToSuperview().inset(18)
$0.height.equalTo(2)
}
}

private func setConfiguration() {
setTitleLabel()
setIndicatorBar()
}

private func setTitleLabel() {
titleLabel.text = title
titleLabel.style = switch size {
case .small:
String.HandyTypoStyle.B3Sb14
case .large:
String.HandyTypoStyle.B1Sb16
}
}

private func setIndicatorBar() {
activeIndicatorBar.backgroundColor = HandySemantic.bgBasicBlack
activeIndicatorBar.layer.cornerRadius = 1
activeIndicatorBar.isHidden = !isSelected
}
}

extension HandyTabComponent {
public enum SizeType {
case small
case large
}
}
2 changes: 1 addition & 1 deletion Handy/Handy-Storybook/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
guard let windowScene = (scene as? UIWindowScene) else { return }
window = UIWindow(frame: UIScreen.main.bounds)
window?.windowScene = windowScene
window?.rootViewController = HandyListViewController()
window?.rootViewController = TabsViewController()
window?.makeKeyAndVisible()
}

Expand Down
4 changes: 4 additions & 0 deletions Handy/Handy.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
02ED764C2C57BD09001569F1 /* HandyBoxButtonViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02ED764B2C57BD09001569F1 /* HandyBoxButtonViewController.swift */; };
2D41E8142C5A21930043161D /* FabViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D41E8132C5A21930043161D /* FabViewController.swift */; };
2D41E8162C5A21B50043161D /* HandyFab.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D41E8152C5A21B50043161D /* HandyFab.swift */; };
6FD1A1802D213129001E6F2E /* TabsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FD1A17F2D21311C001E6F2E /* TabsViewController.swift */; };
A56B3DE22C4E51D300C3610A /* HandyChip.swift in Sources */ = {isa = PBXBuildFile; fileRef = A56B3DE12C4E51D300C3610A /* HandyChip.swift */; };
A5A12A7E2C57A6D900996916 /* ChipViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5A12A7C2C57A6C200996916 /* ChipViewController.swift */; };
A5A12A7F2C57A92000996916 /* HandySematic.swift in Sources */ = {isa = PBXBuildFile; fileRef = E5D02AFC2C46C5A70056CE7B /* HandySematic.swift */; };
Expand Down Expand Up @@ -121,6 +122,7 @@
02ED764B2C57BD09001569F1 /* HandyBoxButtonViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HandyBoxButtonViewController.swift; sourceTree = "<group>"; };
2D41E8132C5A21930043161D /* FabViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FabViewController.swift; sourceTree = "<group>"; };
2D41E8152C5A21B50043161D /* HandyFab.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HandyFab.swift; sourceTree = "<group>"; };
6FD1A17F2D21311C001E6F2E /* TabsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabsViewController.swift; sourceTree = "<group>"; };
A56B3DE12C4E51D300C3610A /* HandyChip.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HandyChip.swift; sourceTree = "<group>"; };
A5A12A7C2C57A6C200996916 /* ChipViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChipViewController.swift; sourceTree = "<group>"; };
A5F6D36A2C96F32D00FB961F /* HandyDivider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HandyDivider.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -183,6 +185,7 @@
025776482C4EB0E700272EC6 /* Atom */ = {
isa = PBXGroup;
children = (
6FD1A17F2D21311C001E6F2E /* TabsViewController.swift */,
02150E4B2CCABAE500EE690E /* SnackbarViewController.swift */,
025776382C4EA98C00272EC6 /* LabelViewController.swift */,
2D41E8132C5A21930043161D /* FabViewController.swift */,
Expand Down Expand Up @@ -485,6 +488,7 @@
02ED764C2C57BD09001569F1 /* HandyBoxButtonViewController.swift in Sources */,
E51FBFA22C54CD350097B0DA /* RadioButtonViewController.swift in Sources */,
E51FBF9B2C5399A00097B0DA /* CheckBoxViewController.swift in Sources */,
6FD1A1802D213129001E6F2E /* TabsViewController.swift in Sources */,
025776352C4EA98C00272EC6 /* AppDelegate.swift in Sources */,
02697A262C99DDA30027A362 /* HansySwitchViewController.swift in Sources */,
025776372C4EA98C00272EC6 /* SceneDelegate.swift in Sources */,
Expand Down

0 comments on commit c15f4d5

Please sign in to comment.