Skip to content

Commit

Permalink
[#12] 디자인 디테일 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
chongin12 committed Jan 9, 2025
1 parent 1f7008e commit 092e1bc
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 25 deletions.
29 changes: 22 additions & 7 deletions Handy/Handy-Storybook/Atom/TabsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
//

import Handy
import UIKit

final class TabsViewController: BaseViewController {
private let tabs: HandyTabs = {
let tabs = HandyTabs(sizeType: .small)
tabs.tabs = [
let tabs: [(title: String, viewController: UIViewController)]
init(_ tabCount: Int) {
self.tabs = [
{
let viewController = SnackbarViewController()
return ("SnackbarViewController", viewController)
Expand Down Expand Up @@ -47,17 +48,31 @@ final class TabsViewController: BaseViewController {
let viewController = HansySwitchViewController()
return ("HansySwitchViewController", viewController)
}(),
]
][..<tabCount].map { $0 }
super.init(nibName: nil, bundle: nil)
}

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

override func viewDidLoad() {
super.viewDidLoad()
self.handyTabs.tabs = self.tabs
}

private let handyTabs: HandyTabs = {
let tabs = HandyTabs(sizeType: .small)
return tabs
}()

override func setViewHierarchies() {
self.addChild(tabs)
self.view.addSubview(tabs.view)
self.addChild(handyTabs)
self.view.addSubview(handyTabs.view)
}

override func setViewLayouts() {
tabs.view.snp.makeConstraints {
handyTabs.view.snp.makeConstraints {
$0.edges.equalTo(self.view.safeAreaLayoutGuide)
}
}
Expand Down
4 changes: 3 additions & 1 deletion Handy/Handy-Storybook/Storybook/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ class MainViewController: UITableViewController {
.init(("CheckBoxViewController", CheckBoxViewController())),
.init(("RadioButtonViewController", RadioButtonViewController())),
.init(("HansySwitchViewController", HansySwitchViewController())),
.init(("TabsViewController", TabsViewController())),
.init(("TabsViewController(2개)", TabsViewController(2))),
.init(("TabsViewController(3개)", TabsViewController(3))),
.init(("TabsViewController(9개)", TabsViewController(9))),
]

override func viewDidLoad() {
Expand Down
15 changes: 6 additions & 9 deletions Handy/Handy/Source/Atom/HandyTabs/HandyTabComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ open class HandyTabComponent: UICollectionViewCell {
}
}

// MARK: - private properties
// MARK: - internal & private properties

/// title이 표시될 label입니다.
private let titleLabel: HandyLabel = {
internal let titleLabel: HandyLabel = {
let label = HandyLabel(style: .B1Sb16)
label.alignment = .center
return label
}()

/// 현재 선택됨을 알려주는, 아래쪽에 표시되는 검은색 바입니다.
private let selectedIndicator = UIView()
internal let selectedIndicator = UIView()

// MARK: - init
public override init(frame: CGRect) {
Expand All @@ -57,7 +57,7 @@ open class HandyTabComponent: UICollectionViewCell {
}

// MARK: - private methods

private func initializeViewHierarchy() {
// Set View Hierarchy
self.addSubview(titleLabel)
Expand All @@ -68,18 +68,15 @@ open class HandyTabComponent: UICollectionViewCell {
// Set Constraints
titleLabel.snp.makeConstraints {
$0.leading.trailing.equalToSuperview().inset(16).priority(999)
$0.top.bottom.equalToSuperview().inset(12).priority(999)
$0.centerY.equalToSuperview()
$0.height.equalTo(48)
}

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

self.snp.makeConstraints {
$0.height.equalTo(48)
}
}

private func setConfiguration() {
Expand Down
17 changes: 9 additions & 8 deletions Handy/Handy/Source/Atom/HandyTabs/HandyTabs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ open class HandyTabs: UIViewController {
}
}

/// Tab 간 간격을 의미합니다.
private let tabSpacing: CGFloat = 8.0

// MARK: - Init
public init(sizeType: HandyTabComponent.SizeType) {
self.sizeType = sizeType
Expand Down Expand Up @@ -146,15 +143,19 @@ open class HandyTabs: UIViewController {
private func updateTabsHeaderLayout() {
let layout = UICollectionViewFlowLayout()
layout.scrollDirection = .horizontal
layout.minimumInteritemSpacing = tabSpacing
layout.minimumLineSpacing = 0.0
layout.minimumInteritemSpacing = 0.0

switch tabsType {
case .scrollable:
layout.estimatedItemSize = CGSize(width: 0, height: 48)
case .fixed(let viewCount):
let totalSpacing = tabSpacing * CGFloat(viewCount - 1)
let itemWidth = (self.view.frame.width - totalSpacing) / CGFloat(viewCount)
layout.estimatedItemSize = CGSize(width: 10, height: 48)

self.tabsHeader.isScrollEnabled = true
case .fixed(let tabCount):
let itemWidth = self.view.bounds.width / CGFloat(tabCount)
layout.itemSize = CGSize(width: itemWidth, height: 48)

self.tabsHeader.isScrollEnabled = false
}

tabsHeader.collectionViewLayout = layout
Expand Down

0 comments on commit 092e1bc

Please sign in to comment.