๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐ŸŽ iOS/UI

[iOS/UI] ๋„ค๋น„๊ฒŒ์ด์…˜ ๋ฐ” ๋ฐฑ๋ฒ„ํŠผ ์ปค์Šคํ…€ํ•˜๊ธฐ(UINavigationBarItem Custom)

by Fomagran ๐Ÿ’ป 2020. 2. 28.
728x90
๋ฐ˜์‘ํ˜•

ํŠน์ • ๋„ค๋น„๊ฒŒ์ด์…˜ ์ปจํŠธ๋กค๋Ÿฌ์—์„œ ํ™”๋ฉด์„ ์ด๋™ํ•  ๋•Œ ์ž๋™์œผ๋กœ ๋ฐฑ๋ฒ„ํŠผ์ด ์ƒ๊ธฐ๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋Š”๋ฐ

๋‚˜๋Š” ๋‚ด๊ฐ€ ์›ํ•˜๋Š” ์•„์ด์ฝ˜์œผ๋กœ ๋„์šฐ๊ณ  ๋ฐฑ๋ฒ„ํŠผ๊ณผ ๋˜‘๊ฐ™์€ ๊ธฐ๋Šฅ์„ ๊ฐ–์ถ”๊ฒŒ ํ•˜๊ณ ์‹ถ์—ˆ๋‹ค.

๋ฐ”๋ฒ„ํŠผ์•„์ดํ…œ์—์„œ ์ž์‹ ์ด ์›ํ•˜๋Š” ์ด๋ฏธ์ง€์™€ style tagget action์„ ๋งŒ๋“ค์–ด์ค€ ๋’ค

๋„ค๋น„๊ฒŒ์ด์…˜ ์•„์ดํ…œ์—์„œ ์™ผ์ชฝ ๋ฐ”๋ฒ„ํŠผ ์•„์ดํ…œ์— ๋งŒ๋“ค์–ด ์ค€ ๋ฐ”๋ฒ„ํŠผ ์•„์ดํ…œ์„ ์„ค์ •ํ•ด์ค€๋‹ค.

1
2
 let backbutton = UIBarButtonItem(image: UIImage(named: "passwordOn@3x.png"), style: .done, target: self, action: #selector(back))
 self.navigationItem.leftBarButtonItem = backbutton
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter

action์— #selector(@objc)์— ๋„ฃ์–ด์ค€๋‹ค.

๋„ค๋น„๊ฒŒ์ด์…˜์—์„œ ๊ทธ ์ „ ํ™”๋ฉด์œผ๋กœ ์ด๋™ํ•˜๊ฒŒ ํ•˜๋Š” @objcํ•จ์ˆ˜

1
2
3
  @objc func back() {
        self.navigationController?.popViewController(animated: true)
    }
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter

์•„๋ž˜์™€ ๊ฐ™์ด ์„ค์ •ํ•œ ์ด๋ฏธ์ง€๋กœ ๋ฐฑ๋ฒ„ํŠผ ์•„์ดํ…œ์ด ์ƒ์„ฑ๋˜๊ณ  ๋ˆ„๋ฅด๋ฉด ๋‹ค์‹œ ์ „ ํ™”๋ฉด์œผ๋กœ ๋Œ์•„๊ฐ€๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

728x90
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€