(SWIFT) Toast

2019. 4. 25. 16:45iOS

반응형

    static func showToast(message : String, uiViewController : UIViewController) {

        let toastLabel = UILabel(frame: CGRect(x: uiViewController.view.frame.size.width / 2 - 175, y: uiViewController.view.frame.size.height - 100, width: 350, height: 40))

        toastLabel.backgroundColor = UIColor.black.withAlphaComponent(0.8)

        toastLabel.textColor = UIColor.white

        toastLabel.textAlignment = .center;

        toastLabel.font = UIFont(name: "Montserrat-Light", size: 12.0)

        toastLabel.text = message

        toastLabel.alpha = 1.0

        toastLabel.layer.cornerRadius = 10;

        toastLabel.clipsToBounds  =  true

        // toastLabel.sizeToFit() => text 길이에 맞게, UILabel은 기본으로 선언(let toastLabel = UILabel())

        uiViewController.view.addSubview(toastLabel)

        UIView.animate(withDuration: 4.0, delay: 0.1, options: .curveEaseOut, animations: {

            toastLabel.alpha = 0.0

        }, completion: {(isCompleted) in

            toastLabel.removeFromSuperview()

        })

    }

반응형

'iOS' 카테고리의 다른 글

(SWIFT) Http  (0) 2019.04.25
(SWIFT) JSON Parse  (0) 2019.04.25
(SWIFT) 화면 전환  (0) 2019.04.25
concerning launch image  (0) 2019.04.24
iOS 런처이미지 사이즈표  (0) 2019.04.24