250x250
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- ipad
- MAC
- xcode
- iPhone
- keyframes
- hover
- 풀스택
- php
- javascript
- HTML
- image
- CSS
- SWIFT
- front-end
- 프론트엔드
- html5
- Animation
- react
- 백엔드
- IOS
- jQuery
- effect
- iOS 개발자
- 자바스크립트
- button
- 비전공자
- css3
- 애니메이션
- 비전공 개발자
- 개발자
Archives
- Today
- Total
비전공자 개발일기
Text Field & Delegate 본문
728x90
SMALL
import UIKit
class ViewController: UIViewController, UITextFieldDelegate {
@IBOutlet weak var textField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
textField.delegate = self
setup()
}
func setup() {
view.backgroundColor = UIColor.gray
textField.placeholder = "Input Ur Email Address"
textField.keyboardType = UIKeyboardType.emailAddress
textField.borderStyle = .roundedRect
textField.clearButtonMode = .always
textField.returnKeyType = .go
textField.becomeFirstResponder()
}
// click anywhere in iPhone and close keyboard
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
self.view.endEditing(true)
// textField.resignFirstResponder()
}
// Called when text field input starts
func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
return true
}
// Input start (point of view)
func textFieldDidBeginEditing(_ textField: UITextField) {
print("U stared typing")
}
func textFieldShouldClear(_ textField: UITextField) -> Bool {
return true
}
// Check one word in text field (input or delete)
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
// print(string)
// return true
// Limit length of characters
let maxLength = 10
let currentString: NSString = (textField.text ?? "") as NSString
let newString: NSString = currentString.replacingCharacters(in: range, with: string) as NSString
return newString.length <= maxLength
}
// Whether to allow the next action when the enter key in the text field is pressed
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
return true
}
// Called at the end of textfield input
func textFieldShouldEndEditing(_ textField: UITextField) -> Bool {
return true
}
// When textfield input is complete
// func textFieldDidEndEditing(_ textField: UITextField) {
// <#code#>
// }
@IBAction func doneBTN(_ sender: UIButton) {
textField.resignFirstResponder()
}
}
728x90
LIST
'SWIFT' 카테고리의 다른 글
BMI Calculator (0) | 2022.12.08 |
---|---|
Login View (0) | 2022.12.07 |
Timer App (0) | 2022.12.05 |
[SWIFT] Coding Test Practice Day 3 (0) | 2022.11.09 |
[SWIFT] Coding Test Practice Day 2 (0) | 2022.11.08 |