-
iOS [Swift] - Toast MessageiOS Develop 2022. 3. 17. 11:08반응형
안드로이드엔 있지만 iOS에서는 따로 제공해주지 않는 토스트 메세지를 출력하는 코드를 정리하겠숨돠
나중에 쓸 일이 있겠쥐..ㅎ
func presentToastMessage(message : String, font: UIFont = UIFont.systemFont(ofSize: 15.0)) { let toastLabel = UILabel(frame: CGRect(x: self.view.frame.size.width/2 - 75, y: self.view.frame.size.height-300, width: 150, height: 35)) toastLabel.backgroundColor = UIColor.black.withAlphaComponent(0.6) toastLabel.textColor = UIColor.white toastLabel.font = font toastLabel.textAlignment = .center; toastLabel.text = message toastLabel.alpha = 1.0 toastLabel.layer.cornerRadius = 10; toastLabel.clipsToBounds = true self.view.addSubview(toastLabel) UIView.animate(withDuration: 4.0, delay: 0.2, options: .curveEaseOut, animations: { toastLabel.alpha = 0.0 }, completion: { (isCompleted) in toastLabel.removeFromSuperview() }) }이러고 필요할 때 호출하면 끝~
'iOS Develop' 카테고리의 다른 글
iOS [Swift] - WatchOS HealthKit Background (0) 2022.03.23 iOS [Swift] - WatchOS 화면 Push & 값 전달하기 (0) 2022.03.21 iOS [Swift] - NotificationCenter 사용하기 (0) 2022.03.20 iOS [Swift] - Delegate Pattern (델리게이트 패턴) (0) 2022.03.09 iOS [Swift] - Alamofire 통신 (0) 2022.03.09