Skip to content

Commit

Permalink
Merge pull request #22 from U-is-Ni-in-Korea/feat_21_ryu
Browse files Browse the repository at this point in the history
✨[FEAT] : 토스트 메세지 추가
  • Loading branch information
ryuchanghwi authored Jul 18, 2023
2 parents fd5bfc9 + 7c72e67 commit 5f91d33
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Sources/SDSKit/Component/NavigationBar/SDSNavigationBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,38 +28,38 @@ public class SDSNavigationBar: UIView {
return button
}()

lazy var titleLabel: UILabel = {
public lazy var titleLabel: UILabel = {
let label = UILabel()
label.textColor = .gray600
label.text = navigationTitle
label.font = SDSFont.subTitle.font
return label
}()

lazy var rightBarLeftButtonItem: UIButton = {
public lazy var rightBarLeftButtonItem: UIButton = {
let button = UIButton()
if rightBarButtonImages.count == 2{
button.setImage(rightBarButtonImages[1], for: .normal)
}
return button
}()

lazy var rightBarRightButtonItem: UIButton = {
public lazy var rightBarRightButtonItem: UIButton = {
let button = UIButton()
if rightBarButtonImages.count >= 1 {
button.setImage(rightBarButtonImages[0], for: .normal)
}
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
}()
Expand Down
32 changes: 32 additions & 0 deletions Sources/SDSKit/Component/ToastMessage/SDS-ToastView+.swift
Original file line number Diff line number Diff line change
@@ -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()
})
}
}
49 changes: 49 additions & 0 deletions Sources/SDSKit/Component/ToastMessage/SDSToastView.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}
}

0 comments on commit 5f91d33

Please sign in to comment.