-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from U-is-Ni-in-Korea/feat_21_ryu
✨[FEAT] : 토스트 메세지 추가
- Loading branch information
Showing
3 changed files
with
86 additions
and
5 deletions.
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
32 changes: 32 additions & 0 deletions
32
Sources/SDSKit/Component/ToastMessage/SDS-ToastView+.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,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() | ||
}) | ||
} | ||
} |
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,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) | ||
} | ||
} | ||
} |