์ƒ์„ธ ์ปจํ…์ธ 

๋ณธ๋ฌธ ์ œ๋ชฉ

[iOS] toast message - ๋ฐฐ๋‹ฌ์˜ ๋ฏผ์กฑ ์žฅ๋ฐ”๊ตฌ๋‹ˆ์— ์ถ”๊ฐ€๋์Šต๋‹ˆ๋‹ค

๐ŸŽ iOS/UIKit

by AHN.Jihyeon 2024. 7. 7. 14:20

๋ณธ๋ฌธ

์ด๋ฒˆ ํŒ€ ํ”„๋กœ์ ํŠธ๋Š” ํ•˜๋‚˜์˜ ํ™”๋ฉด์—์„œ ๊ฒฐ์ œ๊นŒ์ง€ ์ด๋ฃจ์–ด์ง€๋Š” ๊ณผ์ œ์˜€๋‹ค. 

๊ณ ๋ฏผ์„ ํ•˜๋‹ค ์žฅ๋ฐ”๊ตฌ๋‹ˆ ํŽ˜์ด์ง€๊ฐ€ ๋”ฐ๋กœ ๋งŒ๋“ค ์ˆ˜๊ฐ€ ์—†์–ด์„œ ํ•˜ํ”„ ๋ชจ๋‹ฌ์„ ๋„์šฐ๊ธฐ๋กœ ํ–ˆ๋‹ค. 

๊ทธ๋Ÿฌ๋‚˜ ๋ชจ๋‹ฌ์„ ์—ด๊ธฐ ์ „๊นŒ์ง„ ์žฅ๋ฐ”๊ตฌ๋‹ˆ์— ์ƒํ’ˆ์ด ์ œ๋Œ€๋กœ ๋‹ด๊ฒผ๋Š”์ง€ ํ™•์ธํ•˜๊ธฐ๊ฐ€ ์‰ฝ์ง€ ์•Š์•˜๋‹ค.  

 

๊ทธ๋ž˜์„œ ์‹ค์ œ๋กœ ๋‹ค๋ฅธ ์•ฑ๋“ค์€ ์–ด๋–ค ๋ฐฉ์‹์œผ๋กœ ๊ตฌํ˜„ํ–ˆ๋Š”์ง€ ๋‹ค์–‘ํ•œ ์–ดํ”Œ๋“ค์„ ๊น”์•„๋ณด๊ณ  ์ฐพ์•„๋ณด์•˜๋‹ค. 

(์ด๋ ‡๊ฒŒ ํ…Œ์ŠคํŠธํ•˜๋‹ค ์‹ค์ œ๋กœ ์Šคํƒ€๋ฒ…์Šค ์‚ฌ์ด๋ Œ ์˜ค๋” ์ž๋™๊ฒฐ์ œ๋กœ ๋„˜์–ด๊ฐ€์„œ ํŠธ๋ Œํƒ€ ์‚ฌ์ด์ฆˆ ์•„์ด์Šคํ‹ฐ ๋งค์žฅ ํ”ฝ์—…ํ•˜๊ฒŒ ๋๋‹ค๋Š” ์ฐ๊ณผ ํ•จ๊ป˜....โ˜†)

๊ทธ์ค‘์—์„œ ๋‚˜๋Š” ๋ฐฐ๋‹ฌ์˜ ๋ฏผ์กฑ์˜ ์žฅ๋ฐ”๊ตฌ๋‹ˆ์— ๋‹ด๋Š” ๊ธฐ๋Šฅ์ด ์ ํ•ฉํ•ด ๋ณด์˜€๋‹ค. 

 

 

๋ฐ”๋กœ ์ด ๊ธฐ๋Šฅ์ด๋‹ค!!!

๊ทผ๋ฐ ๊ตฌํ˜„ํ•˜๊ณ  ์‹ถ์€๋ฐ ๋ญ๋ผ๊ณ  ๊ฒ€์ƒ‰ํ•ด์•ผํ• ์ง€ ๊ฐ์กฐ์ฐจ ์˜ค์ง€ ์•Š์•˜๋‹ค...

๋ฐฐ๋‹ฌ์˜ ๋ฏผ์กฑ ์žฅ๋ฐ”๊ตฌ๋‹ˆ ๋‹ด๊ธธ ๋•Œ, ์žฅ๋ฐ”๊ตฌ๋‹ˆ์— ๋‹ด๊ธฐ๋Š” ์• ๋‹ˆ๋ฉ”์ด์…˜ ๋“ฑ๋“ฑ

์ •๋ง ๋‹ค์–‘ํ•œ ๊ฒ€์ƒ‰์–ด๋กœ ์ฐพ์•„๋ณด๊ณ  ํŠœํ„ฐ๋‹˜๋“ค๊ณผ ๋งค๋‹ˆ์ €๋‹˜๋“ค๋„ ์ฐพ์•„๊ฐ€๋ณด์•˜๋Š”๋ฐ

ํ•˜ํ•„ ๋‚ด๊ฐ€ ๊ฐˆ ๋•Œ๋งˆ๋‹ค ์•„๋ฌด๋„ ์•ˆ ๊ณ„์…จ๋‹ค....

 

์‹œ๊ฐ„์ด ๊ทธ๋ ‡๊ฒŒ ๋งŽ์ง€ ์•Š๊ธฐ๋„ ํ–ˆ๊ณ , ์ •๋ง ๋„ˆ๋ฌด๋„ˆ๋ฌด๋„ˆ๋ฌด ๊ถ๊ธˆํ–ˆ๋‹ค...ใ…‹ใ…‹ใ…‹ใ…‹

๊ทธ๋ž˜์„œ iOS ๊ฐœ๋ฐœ์ž ์˜คํ”ˆ ์ฑ„ํŒ…์„ ์ฐพ์•„์„œ ์งˆ๋ฌธํ–ˆ๋Š”๋ฐ ์ƒ๊ฐ๋ณด๋‹ค ๊ธˆ๋ฐฉ

Toast Message๋ฅผ ์•Œ ์ˆ˜ ์žˆ์—ˆ๋‹คใ…‹ใ…‹ใ…‹ใ…‹

 

 

 

 

 

ํ† ์ŠคํŠธ ๋ฉ”์‹œ์ง€ ์‚ฌ์šฉ ์ฝ”๋“œ 

 

func showToast() {
        let toastLabel = UILabel()
        toastLabel.backgroundColor = UIColor.black.withAlphaComponent(0.7)
        toastLabel.textColor = UIColor.white
        toastLabel.font = UIFont.systemFont(ofSize: 17.0)
        toastLabel.textAlignment = .center
        toastLabel.text = "์žฅ๋ฐ”๊ตฌ๋‹ˆ์— ๋ฉ”๋‰ด๋ฅผ ์ถ”๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค"
        toastLabel.alpha = 1.0
        toastLabel.layer.cornerRadius = 7
        toastLabel.clipsToBounds  =  true
            
        self.view.addSubview(toastLabel)
            
        UIView.animate(withDuration: 0.9, delay: 0.6, options: .curveEaseOut, animations: {
            toastLabel.alpha = 0.0
        }, completion: {(isCompleted) in
            toastLabel.removeFromSuperview()
        })
        
        toastLabel.snp.makeConstraints {
            $0.center.equalToSuperview()
            $0.width.equalTo(280)
            $0.height.equalTo(50)
        }
    }

 

 

 

 

 

 

๐Ÿ”— Reference
https://royhelen.tistory.com/46

๊ด€๋ จ๊ธ€ ๋”๋ณด๊ธฐ