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

๋ณธ๋ฌธ ์ œ๋ชฉ

textField์™€ UIKeyboardType

๐ŸŽ iOS/UIKit

by AHN.Jihyeon 2024. 7. 8. 18:40

๋ณธ๋ฌธ

cmd + k

 

 

 

์‹œ๋ฎฌ๋ ˆ์ดํ„ฐ์—์„œ ์ž๋™์œผ๋กœ ํ‚ค๋ณด๋“œ๊ฐ€ ์˜ฌ๋ผ ์˜ค์ง€ ์•Š๋Š”๋‹ค.

๋”ฐ๋ผ์„œ ์„ค์ •์„ ๋”ฐ๋กœ ํ•ด์ค˜์•ผ ํ•œ๋‹ค. 

 

 

 

 

Toggle Software Keyboard ๋ฅผ ํ™œ์„ฑํ™” ํ•ด์ฃผ๋ฉด ๋!

 

 

 

import UIKit
import SnapKit

class MainViewController: UIViewController {
      
    var textField = UITextField()
    var doneButton = UIButton()
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        view.backgroundColor = UIColor.gray
        configure()
        
    }
    
    
    private func configure() {
        
        [textField, doneButton].forEach {view.addSubview($0)}
        
        //textField ์„ค์ •
        textField.keyboardType = UIKeyboardType.emailAddress //ํ…์ŠคํŠธํ•„๋“œ์— ์ž…๋ ฅํ•  ํ‚ค๋ณด๋“œ ์Šคํƒ€์ผ
        textField.placeholder = "์ด๋ฉ”์ผ ์ž…๋ ฅ"
        textField.borderStyle = .roundedRect //ํ…์ŠคํŠธํ•„๋“œ ์„ 
        textField.clearButtonMode = .always //์ž…๋ ฅํ•œ ๋‚ด์šฉ ์ทจ์†Œ ๋ฒ„ํŠผ ์ƒ์„ฑ
        textField.returnKeyType = .search  //ํ‚ค๋ณด๋“œ์—์„œ ์—”ํ„ฐ ๋ถ€๋ถ„ ์ด๋ฆ„ ๋ฐ”๊พธ๊ธฐ
        
        
        //doneButton ์„ค์ •
        doneButton.setTitle("Done", for: .normal)
        doneButton.backgroundColor = .systemBlue
        
        
        //textField ์˜คํ† ๋ ˆ์ด์•„์›ƒ
        textField.snp.makeConstraints {
            $0.top.equalToSuperview().inset(200)
            $0.leading.equalToSuperview().inset(20)
            $0.width.equalTo(250)
        }
        
        
        //doneButton ์˜คํ† ๋ ˆ์ด์•„์›ƒ
        doneButton.snp.makeConstraints {
            $0.top.equalTo(textField)
            $0.leading.equalTo(textField.snp.trailing).offset(20)
            $0.width.equalTo(60)
        }
    }
}

textField.returnKeyType ์˜ˆ์‹œ

 

 

 

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