From 7c72e676e249f7154c5535a39d96a40f84c6c7f8 Mon Sep 17 00:00:00 2001 From: ryuchanghwi Date: Tue, 18 Jul 2023 16:30:16 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8[FEAT]=20:=20=ED=86=A0=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EB=A9=94=EC=84=B8=EC=A7=80=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NavigationBar/SDSNavigationBar.swift | 10 ++-- .../ToastMessage/SDS-ToastView+.swift | 32 ++++++++++++ .../Component/ToastMessage/SDSToastView.swift | 49 +++++++++++++++++++ 3 files changed, 86 insertions(+), 5 deletions(-) create mode 100644 Sources/SDSKit/Component/ToastMessage/SDS-ToastView+.swift create mode 100644 Sources/SDSKit/Component/ToastMessage/SDSToastView.swift diff --git a/Sources/SDSKit/Component/NavigationBar/SDSNavigationBar.swift b/Sources/SDSKit/Component/NavigationBar/SDSNavigationBar.swift index 088bccb..0ec0adf 100644 --- a/Sources/SDSKit/Component/NavigationBar/SDSNavigationBar.swift +++ b/Sources/SDSKit/Component/NavigationBar/SDSNavigationBar.swift @@ -28,7 +28,7 @@ public class SDSNavigationBar: UIView { return button }() - lazy var titleLabel: UILabel = { + public lazy var titleLabel: UILabel = { let label = UILabel() label.textColor = .gray600 label.text = navigationTitle @@ -36,7 +36,7 @@ public class SDSNavigationBar: UIView { return label }() - lazy var rightBarLeftButtonItem: UIButton = { + public lazy var rightBarLeftButtonItem: UIButton = { let button = UIButton() if rightBarButtonImages.count == 2{ button.setImage(rightBarButtonImages[1], for: .normal) @@ -44,7 +44,7 @@ public class SDSNavigationBar: UIView { return button }() - lazy var rightBarRightButtonItem: UIButton = { + public lazy var rightBarRightButtonItem: UIButton = { let button = UIButton() if rightBarButtonImages.count >= 1 { button.setImage(rightBarButtonImages[0], for: .normal) @@ -52,14 +52,14 @@ public class SDSNavigationBar: UIView { return button }() - let rightBarSingleButtonLabel: UILabel = { + public let rightBarSingleButtonLabel: UILabel = { let label = UILabel() label.textColor = .lightBlue600 label.font = SDSFont.body1.font return label }() - let rightBarSingleButtonItem: UIButton = { + public let rightBarSingleButtonItem: UIButton = { let button = UIButton() return button }() diff --git a/Sources/SDSKit/Component/ToastMessage/SDS-ToastView+.swift b/Sources/SDSKit/Component/ToastMessage/SDS-ToastView+.swift new file mode 100644 index 0000000..a3a55f2 --- /dev/null +++ b/Sources/SDSKit/Component/ToastMessage/SDS-ToastView+.swift @@ -0,0 +1,32 @@ +import Foundation +#if canImport(UIKit) +import UIKit +#endif + +public extension UIView { + + func showToast(message: String, hasSafeArea: Bool) { + let toastMessageView = SDSToastView(toastTitle: message) + + self.addSubview(toastMessageView) + toastMessageView.translatesAutoresizingMaskIntoConstraints = false + if hasSafeArea { + NSLayoutConstraint.activate([ + toastMessageView.centerXAnchor.constraint(equalTo: self.centerXAnchor), + toastMessageView.bottomAnchor.constraint(equalTo: self.bottomAnchor, constant: -47) + ]) + } + else { + NSLayoutConstraint.activate([ + toastMessageView.centerXAnchor.constraint(equalTo: self.centerXAnchor), + toastMessageView.bottomAnchor.constraint(equalTo: self.bottomAnchor, constant: -13) + ]) + } + + UIView.animate(withDuration: 3.0, delay: 0.1, options: .curveEaseInOut, animations: { + toastMessageView.alpha = 0.0 + }, completion: { _ in + toastMessageView.removeFromSuperview() + }) + } +} diff --git a/Sources/SDSKit/Component/ToastMessage/SDSToastView.swift b/Sources/SDSKit/Component/ToastMessage/SDSToastView.swift new file mode 100644 index 0000000..c5d4348 --- /dev/null +++ b/Sources/SDSKit/Component/ToastMessage/SDSToastView.swift @@ -0,0 +1,49 @@ + +#if canImport(UIKit) +import UIKit +import SnapKit +#endif + +public class SDSToastView: UIView { + + public var toastTitle: String + + public lazy var toastTitlelabel: UILabel = { + let label = UILabel() + label.text = toastTitle + label.font = SDSFont.body2.font + label.textColor = .gray000 + + return label + }() + + public init(toastTitle: String) { + self.toastTitle = toastTitle + super.init(frame: .zero) + + setStyle() + setUI() + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + func setUI() { + self.layer.cornerRadius = 19 + self.backgroundColor = .gray450 + } + + func setStyle() { + addSubview(toastTitlelabel) + + self.snp.makeConstraints { + $0.height.equalTo(38) + } + + toastTitlelabel.snp.makeConstraints { + $0.centerX.centerY.equalToSuperview() + $0.leading.trailing.equalToSuperview().inset(18) + } + } +}