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

[iOS/UI] ํ…์ŠคํŠธํ•„๋“œ ์•ˆ์— ์ด๋ฏธ์ง€ ๋„ฃ๊ธฐ ๋ฐ ์—ฌ๋ฐฑ์ฃผ๊ธฐ(UIImage in UITextField and Padding)

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

ํ…์ŠคํŠธํ•„๋“œ ์•ˆ์— ์ด๋ฏธ์ง€๋ฅผ ๋„ฃ๊ณ ์‹ถ์—ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์™ผ์ชฝ์œผ๋กœ ๋„ˆ๋ฌด ์น˜์šฐ์ณ์ ธ ์žˆ๋Š” ๊ฒฝ์šฐ๋„ ์žˆ์–ด์„œ ์ด๋ฏธ์ง€๋Š” ์•ˆ๋„ฃ๊ณ  ์™ผ์ชฝ์— ํŒจ๋”ฉ์„ ์ฃผ๊ณ  ์‹ถ์—ˆ๋‹ค.

ํ…์ŠคํŠธํ•„๋“œ์— ์ต์Šคํ…์…˜์„ ์ฃผ๊ณ  ์ฒซ ๋ฒˆ์งธ์—” ํŒจ๋”ฉ๋ทฐ๋ฅผ ๋”ฐ๋กœ ์ƒ์„ฑํ•ด์„œ width๊ฐ’์œผ๋กœ 10์„ ์ค˜๋ฒ„๋ ค์„œ 10๋งŒํผ ์™ผ์ชฝ์— ํŒจ๋”ฉ์„ ์ฃผ๋Š” ํšจ๊ณผ๋ฅผ ์ฃผ๋Š” ๊ฒƒ์ด๋‹ค.

extension UITextField {
  func addLeftPadding() {
    let paddingView = UIView(frame: CGRect(x: 0, y: 0, width: 10, height: self.frame.height))
    self.leftView = paddingView
    self.leftViewMode = ViewMode.always
  }
    func addleftimage(image:UIImage) {
            let leftimage = UIImageView(frame: CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height))
            leftimage.image = image
            self.leftView = leftimage
            self.leftViewMode = .always
        }
}

 

 

๊ทธ๋ฆฌ๊ณ  ์ด๋ ‡๊ฒŒ ์›ํ•˜๋Š” ํ…์ŠคํŠธํ•„๋“œ์— ํ•จ์ˆ˜๋ฅผ ๋‹ฌ์•„์ฃผ๋ฉด

 

 

์•„๋ž˜ ํ…์ŠคํŠธํ•„๋“œ๋ณด๋‹ค ์™ผ์ชฝ ์—ฌ๋ฐฑ์ด ๋” ์ƒ๊ธด ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

 

 

๊ทธ๋ฆฌ๊ณ  ๋‘ ๋ฒˆ์งธ๋Š” ํ•จ์ˆ˜ ์•ˆ์— ์ด๋ฏธ์ง€ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ์ค˜์„œ ์™ผ์ชฝ์— ํŒจ๋”ฉ๋„ฃ๋Š” ๊ฒƒ๊ณผ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ์ด๋ฏธ์ง€ ๊ฐ€๋กœํฌ๊ธฐ๋งŒํผ width๊ฐ’์„ ์ค˜์„œ ์ด๋ฏธ์ง€๋งŒํผ ์˜ค๋ฅธ์ชฝ์œผ๋กœ ๊ฐ€๊ฒŒ ํ•˜๋Š” ๊ฒƒ์ด๋‹ค. ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ์›ํ•˜๋Š” ํ…์ŠคํŠธํ•„๋“œ์— ํ•จ์ˆ˜๋ฅผ ๋‹ฌ๊ณ  ์›ํ•˜๋Š” ์ด๋ฏธ์ง€๋ฅผ ๋„ฃ์–ด์ฃผ๋ฉด ๋œ๋‹ค!

 

 

์•„๋ž˜์™€ ๊ฐ™์ด ์ด๋ฏธ์ง€๊ฐ€ ์‚ฝ์ž…๋œ ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

 

 

728x90
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€