-
Notifications
You must be signed in to change notification settings - Fork 2
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
Feat [#9] 커스텀 버튼 구현 #10
Merged
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d80818f
Merge branch 'develop' into feat/#9-customButtonUI
kim-seonwoo 85764cb
[Add/#9] Onboarding - OnboardingButton 추가
kim-seonwoo b3db8af
[Feat/#9] Onboarding - button font와 color 추가
kim-seonwoo 05663c9
[Fix/#9] Onboarding - button parameter명 변경
kim-seonwoo 15de001
[Add/#9] Common - HMHSelectButton 파일 추가
kim-seonwoo 5bf28a2
[Feat/#9] Common - HMHSelectButton 기능구현
kim-seonwoo 5ad5fe1
[Feat/#9] Common - HMHSelectButton 다중 선택 타입 구현
kim-seonwoo ceda468
[Feat/#9] Onboarding - button isEnabled로직 추가
kim-seonwoo bcf7f69
[Fix/#9] Common - HMHSelectButton 코드리뷰 반영
kim-seonwoo f6fc57e
[Fix/#9] Onboarding - OnboardingButton 코드리뷰 반영
kim-seonwoo 312c619
[Fix/#9] Onboarding - 커스텀버튼 2차 코드리뷰 반영
kim-seonwoo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
HMH_iOS/HMH_iOS/Presentation/Common/UIComponets/HMHSelectButton.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
// | ||
// HMHSelectButton.swift | ||
// HMH_iOS | ||
// | ||
// Created by Seonwoo Kim on 1/3/24. | ||
// | ||
|
||
import UIKit | ||
|
||
import SnapKit | ||
import Then | ||
|
||
final class HMHSelectButton: UIButton { | ||
@frozen | ||
enum HMHSelectButtonType { | ||
case solitary | ||
case multiple | ||
case disabled | ||
} | ||
|
||
private var selectButtonType: HMHSelectButtonType = .disabled | ||
private var isChecked: Bool = false | ||
|
||
private let buttonContentLabel = UILabel().then { | ||
$0.font = UIFont.iosText5Medium16 | ||
} | ||
|
||
init(buttonType: HMHSelectButtonType, buttonText: String) { | ||
super.init(frame: .zero) | ||
self.selectButtonType = buttonType | ||
buttonContentLabel.text = buttonText | ||
|
||
configureButton() | ||
addTarget() | ||
setUI() | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
private func setUI() { | ||
setHierarchy() | ||
setConstraints() | ||
} | ||
|
||
private func setHierarchy() { | ||
self.addSubview(buttonContentLabel) | ||
} | ||
|
||
private func setConstraints() { | ||
self.snp.makeConstraints { | ||
$0.height.equalTo(62.adjusted) | ||
} | ||
|
||
buttonContentLabel.snp.makeConstraints { | ||
$0.center.equalToSuperview() | ||
} | ||
} | ||
|
||
private func addTarget() { | ||
self.addTarget(self, action: #selector(onboardingButtonTapped), for: .touchUpInside) | ||
} | ||
|
||
private func configureButton() { | ||
self.makeCornerRound(radius: 6.adjustedHeight) | ||
self.layer.cornerCurve = .continuous | ||
|
||
switch selectButtonType { | ||
case .solitary,.multiple: | ||
self.do { | ||
$0.isEnabled = true | ||
$0.backgroundColor = .gray6 | ||
} | ||
|
||
buttonContentLabel.do { | ||
$0.textColor = .whiteText | ||
} | ||
case .disabled: | ||
self.do { | ||
$0.isEnabled = false | ||
$0.backgroundColor = .gray7 | ||
} | ||
|
||
buttonContentLabel.do { | ||
$0.textColor = .gray4 | ||
} | ||
} | ||
} | ||
|
||
private func updateStyle() { | ||
if isChecked { | ||
backgroundColor = .bluePurpleActive | ||
makeBorder(width: 1.5, color: .bluePurpleLine) | ||
} else { | ||
backgroundColor = .gray6 | ||
layer.borderColor = UIColor.clear.cgColor | ||
} | ||
} | ||
|
||
private func setChecked(_ checked: Bool) { | ||
isChecked = checked | ||
updateStyle() | ||
} | ||
|
||
@objc private func onboardingButtonTapped() { | ||
switch selectButtonType { | ||
case .solitary: | ||
guard !isChecked else { return } | ||
|
||
superview?.subviews.forEach { subview in | ||
if let button = subview as? HMHSelectButton, button != self { | ||
button.setChecked(false) | ||
} | ||
} | ||
|
||
setChecked(true) | ||
|
||
case .multiple: | ||
setChecked(!isChecked) | ||
|
||
case .disabled: | ||
return | ||
} | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
HMH_iOS/HMH_iOS/Presentation/Onboarding/Views/OnboardingButton.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// | ||
// OnboardingButton.swift | ||
// HMH_iOS | ||
// | ||
// Created by Seonwoo Kim on 1/3/24. | ||
// | ||
|
||
import UIKit | ||
|
||
import SnapKit | ||
import Then | ||
|
||
final class OnboardingButton: UIButton { | ||
@frozen | ||
enum OnboardingButtonType { | ||
case enable | ||
case disabled | ||
} | ||
|
||
private var type: OnboardingButtonType = .disabled | ||
|
||
private let buttonTitleLabel = UILabel().then { | ||
$0.textColor = .whiteText | ||
$0.font = .iosText4Semibold16 | ||
} | ||
|
||
init(buttonStatus type: OnboardingButtonType, buttonText: String) { | ||
super.init(frame: .zero) | ||
self.type = type | ||
buttonTitleLabel.text = buttonText | ||
|
||
configureButton() | ||
setUI() | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
private func setUI() { | ||
setHierarchy() | ||
setConstraints() | ||
} | ||
|
||
private func setHierarchy() { | ||
self.addSubview(buttonTitleLabel) | ||
} | ||
|
||
private func setConstraints() { | ||
self.snp.makeConstraints { | ||
$0.height.equalTo(52.adjusted) | ||
} | ||
|
||
buttonTitleLabel.snp.makeConstraints { | ||
$0.center.equalToSuperview() | ||
} | ||
} | ||
|
||
private func configureButton() { | ||
self.makeCornerRound(radius: 6.adjustedHeight) | ||
self.layer.cornerCurve = .continuous | ||
|
||
switch type { | ||
case .enable: | ||
self.do { | ||
$0.isEnabled = true | ||
$0.backgroundColor = .bluePurpleButton | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P5. 여기도 위랑 똑같이 |
||
case .disabled: | ||
self.do { | ||
$0.isEnabled = false | ||
$0.backgroundColor = .gray5 | ||
} | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P5. 소소하지만 .. case naming 혹시
enabled
는 어떠신가요?disabled
와 맞추는 게 좋아보여서요!