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

:: [#223] BaseButton 적용 #225

Merged
merged 6 commits into from
Feb 25, 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
39 changes: 33 additions & 6 deletions Projects/Core/Sources/Base/BaseButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,55 @@ import SnapKit

open class BaseButton: UIButton {
public let disposeBag = DisposeBag()

public override init(frame: CGRect) {
super.init(frame: frame)

attribute()
layout()
buttonAction()
}

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

open func attribute() {
// 부가적인 것을 여기에 넣습니다.
}

open func layout() {
// 서브뷰를 구성하고 SnapKit을 사용해서 layout을 하는 함수입니다.
}

open func buttonAction() {
// 버튼을 클릭했을 때의 이벤트를 넣습니다
}

open func setImage(image: UIImage, backImage: UIImage? = UIImage()) {
// 버튼의 이미지를 넣는 함수입니다.
self.setImage(image, for: .normal)
self.setBackgroundImage(backImage, for: .normal)
}

open func setColor(textColor: UIColor? = .black, backColor: UIColor? = .clear) {
// 버튼의 배경 색을 변경하는 함수입니다.
self.setTitleColor(textColor, for: .normal)
self.backgroundColor = backColor
}

open func setCornerRadius(radius: Double) {
// 버튼의 cornerRadius를 설정하는 함수입니다.
self.layer.cornerRadius = radius
}

open func setTitle(text: String) {
// 버튼의 titleText를 설정하는 함수입니다.
self.setTitle(text, for: .normal)
}

open func setFont(font: UIFont) {
// 버튼의 titleLabel font를 설정하는 함수입니다.
self.titleLabel?.font = font
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ public class NicknameViewController: BaseViewController<NicknameViewModel> {

private let nicknameTF = MGTextField(placeholder: "닉네임")

private let cancelButton = UIButton().then {
$0.setImage(DSKitAsset.Assets.cancle.image, for: .normal)
}
private let cancelButton = MGImageButton(image: DSKitAsset.Assets.cancle.image)

private var checkButton = MGCheckButton(text: "회원가입")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@ final class HomeNavigationBar: UIView {
public var rightButtonTap: ControlEvent<Void> {
return rightButton.rx.tap
}

private let logoImageView = UIImageView().then {
$0.image = DSKitAsset.Assets.mainTitle.image.withRenderingMode(.alwaysOriginal)
$0.contentMode = .scaleToFill
}

private let rightButton = UIButton(type: .custom).then {
$0.setImage(DSKitAsset.Assets.setting.image, for: .normal)
}
private let rightButton = MGImageButton(image: DSKitAsset.Assets.setting.image)

private lazy var rightItemsStackView = UIStackView(arrangedSubviews: [rightButton]).then {
$0.axis = .horizontal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,18 @@ public class MetronomeViewController: UIViewController {
$0.font = UIFont.Pretendard.light
}

private let tempoIncrementButton = UIButton().then {
$0.setImage(DSKitAsset.Assets.selfCarePlus.image, for: .normal)
$0.backgroundColor = DSKitAsset.Colors.gray50.color
$0.layer.cornerRadius = 22.0
private let tempoIncrementButton = MGImageButton(
image: DSKitAsset.Assets.selfCarePlus.image,
backColor: DSKitAsset.Colors.gray50.color
).then {
$0.setCornerRadius(radius: 22.0)
}

private let tempoDecrementButton = UIButton().then {
$0.setImage(DSKitAsset.Assets.selfCareMinus.image, for: .normal)
$0.backgroundColor = DSKitAsset.Colors.gray50.color
$0.layer.cornerRadius = 22.0
private let tempoDecrementButton = MGImageButton(
image: DSKitAsset.Assets.selfCareMinus.image,
backColor: DSKitAsset.Colors.gray50.color
).then {
$0.setCornerRadius(radius: 22.0)
}

private let tempoSlider = MGSlider()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ final class MetronomeNavigationBar: UIView {
return rightButton.rx.tap
}

private let rightButton = UIButton(type: .custom).then {
$0.setImage(DSKitAsset.Assets.timerNavDots.image, for: .normal)
}
private let rightButton = MGImageButton(image: DSKitAsset.Assets.timerNavDots.image)

private lazy var rightItemsStackView = UIStackView(arrangedSubviews: [rightButton]).then {
$0.axis = .horizontal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ public class TimerAlarmAlertView: BaseView {
$0.text = "-00:00:00"
}

private let clearButton = UIButton().then {
$0.setTitle("해제", for: .normal)
$0.titleLabel?.font = UIFont.Pretendard.titleSmall
$0.setTitleColor(DSKitAsset.Colors.blue500.color, for: .normal)
}

private let restartButton = UIButton().then {
$0.setTitle("다시 시작", for: .normal)
$0.titleLabel?.font = UIFont.Pretendard.titleSmall
$0.setTitleColor(DSKitAsset.Colors.blue500.color, for: .normal)
}
private let clearButton = MGButton(
titleText: "해제",
font: UIFont.Pretendard.titleSmall,
textColor: DSKitAsset.Colors.blue500.color
)
private let restartButton = MGButton(
titleText: "다시 시작",
font: UIFont.Pretendard.titleSmall,
textColor: DSKitAsset.Colors.blue500.color
)

private let decorationLine = MGLine(lineHeight: 22.0).then {
$0.layer.cornerRadius = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,22 @@ public class TimerEditView: BaseView {
$0.layer.shadowRadius = 6
}

private var firstButton = UIButton().then {
$0.setTitle("타이머 편집", for: .normal)
$0.titleLabel?.font = UIFont.Pretendard.labelMedium
private var firstButton = MGButton(
titleText: "타이머 편집",
font: UIFont.Pretendard.labelMedium,
textColor: .black
).then {
$0.contentHorizontalAlignment = .left
$0.setTitleColor(.black, for: .normal)
}

private var secondButton = UIButton().then {
$0.setTitle("설정", for: .normal)
$0.titleLabel?.font = UIFont.Pretendard.labelMedium
private var secondButton = MGButton(
titleText: "설정",
font: UIFont.Pretendard.labelMedium,
textColor: .black
).then {
$0.contentHorizontalAlignment = .left
$0.setTitleColor(.black, for: .normal)
}

public override init(frame: CGRect) {
super.init(frame: frame)
self.isHidden = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,11 @@ public class TimerViewController: BaseViewController<TimerViewModel> {

private var alaertView = TimerAlarmAlertView()

private var navBeforeButton = UIButton().then {
$0.setImage(DSKitAsset.Assets.timerNavLeft.image, for: .normal)
}
private var navBeforeButton = MGImageButton(image: DSKitAsset.Assets.timerNavLeft.image)

private var navAddButton = UIButton().then {
$0.setImage(DSKitAsset.Assets.timerNavPlus.image, for: .normal)
}
private var navAddButton = MGImageButton(image: DSKitAsset.Assets.timerNavPlus.image)

private var navEditButton = UIButton().then {
$0.setImage(DSKitAsset.Assets.timerNavDots.image, for: .normal)
}
private var navEditButton = MGImageButton(image: DSKitAsset.Assets.timerNavDots.image)

private var editView = TimerEditView()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ final public class AlbumNavigationBar: UIView {
return leftButton.rx.tap
}

private let leftButton = UIButton(type: .custom).then {
$0.setImage(DSKitAsset.Assets.arrowLeft.image, for: .normal)
}
private let leftButton = MGImageButton(image: DSKitAsset.Assets.arrowLeft.image)

private let leftLabel = UILabel().then {
$0.font = UIFont.Pretendard.titleMedium
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,28 @@ public class CameraViewController: BaseViewController<CameraViewModel> {
$0.setCameraPosition(.back)
}

private var captureButton = UIButton().then {
$0.setImage(DSKitAsset.Assets.cameraButton.image, for: .normal)
$0.setTitleColor(.black, for: .normal)
private var captureButton = MGButton(
titleText: "",
image: DSKitAsset.Assets.cameraButton.image,
textColor: .black
)

private var photoButton = MGButton(
titleText: "",
image: DSKitAsset.Assets.image.image,
textColor: .black,
backColor: DSKitAsset.Colors.gray800.color
).then {
$0.setCornerRadius(radius: 26.0)
}

private var photoButton = UIButton().then {
$0.backgroundColor = DSKitAsset.Colors.gray800.color
$0.setImage(DSKitAsset.Assets.image.image, for: .normal)
$0.layer.cornerRadius = 26.0
$0.setTitleColor(.black, for: .normal)
}

private var chageButton = UIButton().then {
$0.backgroundColor = DSKitAsset.Colors.gray800.color
$0.setImage(DSKitAsset.Assets.turn.image, for: .normal)
$0.layer.cornerRadius = 26.0
$0.setTitleColor(.black, for: .normal)
private var chageButton = MGButton(
titleText: "",
image: DSKitAsset.Assets.turn.image,
textColor: .black,
backColor: DSKitAsset.Colors.gray800.color
).then {
$0.setCornerRadius(radius: 26.0)
}

public override func configureNavigationBar() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ final public class CameraNavigationBar: UIView {
return leftButton.rx.tap
}

private let leftButton = UIButton(type: .custom).then {
$0.setImage(DSKitAsset.Assets.pickleCancel.image, for: .normal)
}
private let leftButton = MGImageButton(image: DSKitAsset.Assets.pickleCancel.image)

private let leftLabel = UILabel().then {
$0.font = UIFont.Pretendard.titleMedium
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ public class SelfCareMyRoutineDetailViewController: BaseViewController<SelfCareM

private var deleteRoutineButton = SelfCareButton(type: .deleteRotine)
private var editRoutineButton = SelfCareButton(type: .editRoutine)
private var dotsButton = UIButton().then {
$0.setImage(DSKitAsset.Assets.selfCareDots.image, for: .normal)
}
private var dotsButton = MGImageButton(image: DSKitAsset.Assets.selfCareDots.image)

public override func attribute() {
super.attribute()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,9 @@ public class MyRoutineCountView: BaseView {
$0.layer.borderWidth = 1
}

private var minusButton = UIButton().then {
$0.setImage(DSKitAsset.Assets.selfCareMinus.image, for: .normal)
$0.backgroundColor = .clear
}
private var minusButton = MGImageButton(image: DSKitAsset.Assets.selfCareMinus.image)

private var plusButtonn = UIButton().then {
$0.setImage(DSKitAsset.Assets.selfCarePlus.image, for: .normal)
$0.backgroundColor = .clear
}
private var plusButtonn = MGImageButton(image: DSKitAsset.Assets.selfCarePlus.image)

private var numberTextField = UITextField().then {
$0.font = UIFont.Pretendard.bodyMedium
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ public class MyRoutineEditTableViewCell: BaseTableViewCell {
$0.font = UIFont.Pretendard.bodyMedium
}

private var deleteButton = UIButton().then {
$0.setImage(DSKitAsset.Assets.selfCareDelete.image, for: .normal)
}
private var deleteButton = MGImageButton(image: DSKitAsset.Assets.selfCareDelete.image)

private let numberCountView = MyRoutineCountView()
private let setCountView = MyRoutineCountView()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ public class MyRoutineTableViewCell: BaseTableViewCell {
$0.isHidden = true
}

private let dotsButton = UIButton().then {
$0.setImage(DSKitAsset.Assets.selfCareDots.image, for: .normal)
}
private let dotsButton = MGImageButton(image: DSKitAsset.Assets.selfCareDots.image)

public func setup(with model: SelfCareRoutineModel) {
routineNameLabel.text = model.routineNameText
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ public class TargetMainTableViewCell: BaseTableViewCell {
$0.textColor = DSKitAsset.Colors.gray400.color
}

private let dotsButton = UIButton().then {
$0.setImage(DSKitAsset.Assets.selfCareDots.image, for: .normal)
}
private let dotsButton = MGImageButton(image: DSKitAsset.Assets.selfCareDots.image)

public func setup(with model: TargetContentModel) {
changeTargetName(text: model.targetTitle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ public class DSAlertViewController: UIViewController {
$0.backgroundColor = .gray
}

let caveatAlertButton = UIButton().then {
$0.backgroundColor = .red
$0.setTitle("caveatAlert", for: .normal)
}
let caveatAlertButton = MGButton(
titleText: "caveatAlert",
backColor: .red
)

public override func viewDidLoad() {
super.viewDidLoad()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public class DSBottomSheetViewController: UIViewController {
bottomSheetView?.layer.shadowOffset = CGSize(width: 0, height: 5.0)
bottomSheetView?.layer.shadowRadius = 5
bottomSheetView?.layer.shadowOpacity = 0.5
let hideButton = UIButton(type: .system)
hideButton.setTitle("Hide BottomSheet", for: .normal)

let hideButton = MGButton(titleText: "Hide BottomSheet")

hideButton.addTarget(self, action: #selector(hideBottomSheet), for: .touchUpInside)

view.addSubview(hideButton)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ public class DSTextFieldViewController: UIViewController {
private let nicknameLabel = MGLabel(text: "닉네임")
private let nicknameInfo = MGLabel(text: "자신만의 닉네임을 입력해 주세요.", font: UIFont.Pretendard.bodyMedium)

private let cancelButton = UIButton().then {
$0.setImage(DSKitAsset.Assets.cancle.image, for: .normal)
}

private let cancelButton = MGImageButton(image: DSKitAsset.Assets.cancle.image)

public let completeButton = MGCheckButton(text: "완료")

public let nicknameTF = MGTextField(placeholder: "닉네임")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,12 @@ open class MGCaveatAlertViewController: UIViewController {
completion: (() -> Void)? = nil) {
guard let title = title else { return }

let button = UIButton().then {
$0.titleLabel?.font = .systemFont(ofSize: 16.0, weight: .bold)

$0.setTitle(title, for: .normal)
$0.setTitleColor(titleColor, for: .normal)
let button = MGButton(
titleText: title,
font: .systemFont(ofSize: 16.0, weight: .bold),
textColor: .gray
).then {
$0.setBackgroundImage(backgroundColor.image(), for: .normal)

$0.setTitleColor(.gray, for: .disabled)
$0.setBackgroundImage(UIColor.gray.image(), for: .disabled)

$0.layer.cornerRadius = 4.0
Expand Down
Loading