Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
189 changes: 189 additions & 0 deletions iBox/Sources/Base/BaseNavigationBarViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
//
// BaseNavigationBarViewController.swift
// iBox
//
// Created by jiyeon on 1/3/24.
//

import UIKit

import SnapKit

class NavigationBar: UIView {
var backButton = UIButton()
var titleLabel = UILabel()
var addButton = UIButton()
}

protocol BaseNavigationBarViewControllerProtocol {
var statusBar: UIView { get }
var navigationBar: NavigationBar { get }
var contentView: BaseView { get }

func setupNavigationBar()
func setNavigationBarBackgroundColor(_ color: UIColor?)
func setNavigationBarTintColor(_ color: UIColor)
func setNavigationBarHidden(_ hidden: Bool)
func setNavigationBarBackButtonHidden(_ hidden: Bool)
func setNavigationBarAddButtonHidden(_ hidden: Bool)
func setNavigationBarTitleLabelText(_ text: String?)
func setNavigationBarTitleLabelFont(_ font: UIFont?)
func setNavigationBarTitleLabelTextColor(_ color: UIColor?)
}

class BaseNavigationBarViewController<View: BaseView>: UIViewController, BaseNavigationBarViewControllerProtocol {

// MARK: - UI

let statusBar = UIView()

let navigationBar = NavigationBar().then {
$0.backButton.configuration = .plain()
$0.backButton.configuration?.image = UIImage(systemName: "chevron.left")
$0.backButton.configuration?.preferredSymbolConfigurationForImage = .init(weight: .bold)
$0.addButton.configuration = .plain()
$0.addButton.configuration?.image = UIImage(systemName: "plus")
$0.addButton.configuration?.preferredSymbolConfigurationForImage = .init(weight: .bold)
}

let contentView: BaseView = View()

// MARK: - properties

let backgroundColor: UIColor = .systemBackground
let tintColor: UIColor = .black
let titleFont: UIFont = .systemFont(ofSize: 20, weight: .semibold)

// MARK: - life cycle

override func viewDidLoad() {
super.viewDidLoad()
configureUI()
setupNavigationBar()
setupProperties()
}

// MARK: - BaseNavigationBarViewControllerProtocol

func setupNavigationBar() {}

func setNavigationBarBackgroundColor(_ color: UIColor?) {
statusBar.backgroundColor = color
navigationBar.backgroundColor = color
}

func setNavigationBarTintColor(_ color: UIColor) {
navigationBar.backButton.tintColor = color
navigationBar.addButton.tintColor = color
}

func setNavigationBarHidden(_ hidden: Bool) {
navigationBar.isHidden = hidden

if hidden {
contentView.snp.remakeConstraints {
$0.top.equalTo(statusBar.snp.bottom)
$0.leading.trailing.equalTo(view.safeAreaLayoutGuide)
$0.bottom.equalToSuperview()
}
} else {
contentView.snp.remakeConstraints {
$0.top.equalTo(statusBar.snp.bottom).offset(60)
$0.leading.trailing.equalTo(view.safeAreaLayoutGuide)
$0.bottom.equalToSuperview()
}
}
}

func setNavigationBarBackButtonHidden(_ hidden: Bool) {
navigationBar.backButton.isHidden = hidden

if hidden {
navigationBar.titleLabel.snp.remakeConstraints {
$0.left.equalToSuperview().inset(30)
$0.centerY.equalToSuperview()
}
} else {
navigationBar.titleLabel.snp.remakeConstraints {
$0.center.equalToSuperview()
}
}
}

func setNavigationBarAddButtonHidden(_ hidden: Bool) {
navigationBar.addButton.isHidden = hidden
}

func setNavigationBarTitleLabelText(_ text: String?) {
navigationBar.titleLabel.text = text
}

func setNavigationBarTitleLabelFont(_ font: UIFont?) {
navigationBar.titleLabel.font = font
}

func setNavigationBarTitleLabelTextColor(_ color: UIColor?) {
navigationBar.titleLabel.textColor = color
}

// MARK: - functions

private func configureUI() {
view.backgroundColor = .systemBackground
view.addSubview(statusBar)
view.addSubview(navigationBar)
navigationBar.addSubview(navigationBar.backButton)
navigationBar.addSubview(navigationBar.titleLabel)
navigationBar.addSubview(navigationBar.addButton)
view.addSubview(contentView)

statusBar.snp.makeConstraints {
$0.left.top.right.equalToSuperview()
$0.bottom.equalTo(view.safeAreaLayoutGuide.snp.top)
}

navigationBar.snp.makeConstraints {
$0.top.equalTo(statusBar.snp.bottom)
$0.left.right.equalToSuperview()
$0.height.equalTo(60)
}

navigationBar.backButton.snp.makeConstraints {
$0.left.equalToSuperview().inset(20)
$0.centerY.equalToSuperview()
$0.width.height.equalTo(24)
}

navigationBar.titleLabel.snp.makeConstraints {
$0.center.equalToSuperview()
}

navigationBar.addButton.snp.makeConstraints {
$0.right.equalToSuperview().inset(20)
$0.centerY.equalToSuperview()
$0.width.height.equalTo(24)
}

contentView.snp.makeConstraints {
$0.top.equalTo(statusBar.snp.bottom).offset(60)
$0.left.right.equalToSuperview()
$0.bottom.equalToSuperview().inset(tabBarController?.tabBar.frame.height ?? 0)
}
}

private func setupProperties() {
navigationController?.setNavigationBarHidden(true, animated: false)

setNavigationBarTintColor(tintColor)
setNavigationBarTitleLabelFont(titleFont)
setNavigationBarBackButtonHidden(true)
setNavigationBarAddButtonHidden(true)

navigationBar.backButton.addTarget(self, action: #selector(backButtonTapped), for: .touchUpInside)
}

@objc func backButtonTapped() {
navigationController?.popViewController(animated: true)
}

}
31 changes: 31 additions & 0 deletions iBox/Sources/Base/BaseView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// BaseView.swift
// iBox
//
// Created by jiyeon on 1/3/24.
//

import UIKit

protocol BaseViewProtocol {
func configureUI()
}

class BaseView: UIView, BaseViewProtocol {

// MARK: - initializer

override init(frame: CGRect) {
super.init(frame: frame)
configureUI()
}

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

// MARK: - BaseViewProtocol

func configureUI() {}

}
25 changes: 25 additions & 0 deletions iBox/Sources/Extension/UIColor+Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// UIColor+Extension.swift
// iBox
//
// Created by jiyeon on 1/3/24.
//

import UIKit

extension UIColor {

convenience init(hex: UInt, alpha: CGFloat = 1.0) {
self.init(
red: CGFloat((hex & 0xFF0000) >> 16) / 255.0,
green: CGFloat((hex & 0x00FF00) >> 8) / 255.0,
blue: CGFloat(hex & 0x0000FF) / 255.0,
alpha: CGFloat(alpha)
)
}

class var box: UIColor { UIColor(hex: 0xFF7F29) }
class var box2: UIColor { UIColor(hex: 0xFF9548) }
class var box3: UIColor { UIColor(hex: 0xFFDC6E) }

}
21 changes: 21 additions & 0 deletions iBox/Sources/Extension/UIView+Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// UIView+Extension.swift
// iBox
//
// Created by jiyeon on 1/3/24.
//

import UIKit

protocol Then {}

extension Then where Self: AnyObject {

func then(block: (Self) -> Void) -> Self {
block(self)
return self
}

}

extension UIView: Then {}
13 changes: 13 additions & 0 deletions iBox/Sources/Model/DisplayModeItem.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// DisplayModeItem.swift
// iBox
//
// Created by jiyeon on 1/4/24.
//

import UIKit

struct DisplayModeItem {
var title: String
var image: UIImage?
}
19 changes: 19 additions & 0 deletions iBox/Sources/Model/MyPageItem.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// MyPageItem.swift
// iBox
//
// Created by jiyeon on 1/3/24.
//

import UIKit

struct MyPageSection {
var title: String
var items: [MyPageItem]
}

struct MyPageItem {
var title: String
var description: String?
var viewController: UIViewController?
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@
import UIKit

class MainTabBarController: UITabBarController {

override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .systemBackground

setupTabBar()
}

private func setupTabBar() {
viewControllers = [
setupViewController(viewController: BoxListViewController(), image: UIImage(systemName: "square.grid.2x2.fill")),
setupViewController(viewController: FavoriteViewController(), image: UIImage(systemName: "heart.fill")),
setupViewController(viewController: ProfileViewController(), image: UIImage(systemName: "person.fill"))
setupViewController(viewController: MyPageViewController(), image: UIImage(systemName: "person.fill"))
]
tabBar.tintColor = .box
}

private func setupViewController(viewController: UIViewController, image: UIImage?) -> UIViewController {
Expand Down
File renamed without changes.
Loading