Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix [#26] NavigationBar 백그라운드 수정 #27

Merged
merged 7 commits into from
Jan 8, 2024
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
1 change: 1 addition & 0 deletions HMH_iOS/HMH_iOS/Global/Literals/Literal/Image.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import UIKit
enum ImageLiterals {
enum NavigationBar {
static var icArrowLeft: UIImage { .load(named: "ic_back")}
static var icPoint: UIImage { .load(named: "ios_point")}
}

enum TabBar {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "ios_point.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
105 changes: 82 additions & 23 deletions HMH_iOS/HMH_iOS/Presentation/Common/UIComponets/HMHNavigationBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,22 @@ final class HMHNavigationBar: UIView {
}

private var type: NavigationBarType = .normal
private var isGray: Bool = false

private lazy var backArrowButton = UIButton().then {
$0.setImage(ImageLiterals.NavigationBar.icArrowLeft, for: .normal)
$0.isHidden = true
}

private lazy var pointButton = UIButton().then {
$0.backgroundColor = .blue
$0.isHidden = true
}

private let pointImageView = UIImageView().then {
$0.image = ImageLiterals.NavigationBar.icPoint
$0.tintColor = .gray3
}

private let logoImageView = UIImageView().then {
$0.backgroundColor = .blue
}
Expand All @@ -39,17 +44,24 @@ final class HMHNavigationBar: UIView {
$0.isHidden = true
}

init(leftItem type: NavigationBarType, isBackButton: Bool, isTitleLabel: Bool, isPointImage: Bool, titleText: String? = nil) {
init(leftItem type: NavigationBarType,
isBackButton: Bool,
isTitleLabel: Bool,
isPointImage: Bool,
isBackGroundGray: Bool,
titleText: String? = nil) {
Comment on lines +47 to +52
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P5. 가독성이 훨씬 좋아진 것 같아요 좋아요!

super.init(frame: .zero)
self.type = type

backArrowButton.isHidden = !isBackButton
titleLabel.isHidden = !isTitleLabel
pointButton.isHidden = !isPointImage
isGray = isBackGroundGray
titleLabel.text = titleText

setUI()
addTarget()
configureNavigationBar()
}

required init?(coder: NSCoder) {
Expand All @@ -65,36 +77,80 @@ final class HMHNavigationBar: UIView {
switch type {
case .normal:
self.addSubviews(backArrowButton, titleLabel, pointButton)

pointButton.addSubview(pointImageView)
case .logo:
self.addSubviews(logoImageView)
}
}

private func setConstraints() {
switch type {
case .normal:
backArrowButton.snp.makeConstraints {
$0.centerY.equalToSuperview()
$0.leading.equalToSuperview().inset(20.adjusted)
$0.size.equalTo(24.adjusted)
//SE이외의 기기 일때
if UIScreen.main.isLongerThan812pt {
self.snp.makeConstraints {
$0.height.equalTo(113.adjusted)
}

titleLabel.snp.makeConstraints {
$0.center.equalToSuperview()
switch type {
case .normal:
backArrowButton.snp.makeConstraints {
$0.centerY.equalTo(titleLabel)
$0.leading.equalToSuperview().inset(20.adjusted)
$0.size.equalTo(24.adjusted)
}

titleLabel.snp.makeConstraints {
$0.top.equalToSuperview().offset(68.adjusted)
$0.centerX.equalToSuperview()
}

pointButton.snp.makeConstraints {
$0.centerY.equalTo(titleLabel)
$0.trailing.equalToSuperview().inset(20.adjusted)
$0.size.equalTo(24.adjusted)
}

pointImageView.snp.makeConstraints {
$0.edges.equalToSuperview()
}

case .logo:
logoImageView.snp.makeConstraints {
$0.centerY.equalToSuperview().offset(50.adjusted)
$0.leading.equalToSuperview().inset(20.adjusted)
$0.size.equalTo(24.adjusted)
}
}

pointButton.snp.makeConstraints {
$0.centerY.equalToSuperview()
$0.trailing.equalToSuperview().inset(20.adjusted)
$0.size.equalTo(24.adjusted)
} else {
self.snp.makeConstraints {
$0.height.equalTo(83.adjusted)
}

case .logo:
logoImageView.snp.makeConstraints {
$0.centerY.equalToSuperview()
$0.leading.equalToSuperview().inset(20.adjusted)
$0.size.equalTo(24.adjusted)
switch type {
case .normal:
backArrowButton.snp.makeConstraints {
$0.centerY.equalTo(titleLabel)
$0.leading.equalToSuperview().inset(20.adjusted)
$0.size.equalTo(24.adjusted)
}

titleLabel.snp.makeConstraints {
$0.centerX.equalToSuperview()
$0.bottom.equalToSuperview().offset(-18.adjusted)
}

pointButton.snp.makeConstraints {
$0.centerY.equalTo(titleLabel)
$0.trailing.equalToSuperview().inset(20.adjusted)
$0.size.equalTo(24.adjusted)
}

pointImageView.snp.makeConstraints {
$0.edges.equalToSuperview()
}
case .logo:
logoImageView.snp.makeConstraints {
$0.centerY.equalToSuperview().offset(50.adjusted)
$0.leading.equalToSuperview().inset(20.adjusted)
$0.size.equalTo(24.adjusted)
}
}
}
}
Expand All @@ -103,6 +159,9 @@ final class HMHNavigationBar: UIView {
backArrowButton.addTarget(self, action: #selector(backArrowButtonTapped), for: .touchUpInside)
}

private func configureNavigationBar() {
self.backgroundColor = isGray ? .gray7 : .background
}

@objc private func backArrowButtonTapped() {
guard let navigationController = findViewController()?.navigationController else {
Expand Down