-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUITextField+.swift
More file actions
38 lines (33 loc) · 1.13 KB
/
UITextField+.swift
File metadata and controls
38 lines (33 loc) · 1.13 KB
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
29
30
31
32
33
34
35
36
37
38
//
// UITextField+.swift
// Smashing-Assignment
//
// Created by 홍준범 on 12/26/25.
//
import UIKit
import Combine
extension UITextField {
func textDidChangePublisher() -> AnyPublisher<String, Never> {
NotificationCenter.default
.publisher(for: UITextField.textDidChangeNotification, object: self)
.map { _ in self.text ?? "" }
.eraseToAnyPublisher()
}
}
extension UITextField {
func addLeftPadding(_ width: CGFloat = 10) {
let paddingView = UIView(frame: CGRect(x: 0, y: 0, width: width, height: self.frame.height))
self.leftView = paddingView
self.leftViewMode = ViewMode.always
}
func addRightPadding(_ width: CGFloat = 10) {
let paddingView = UIView(frame: CGRect(x: 0, y: 0, width: width, height: self.frame.height))
self.rightView = paddingView
self.rightViewMode = ViewMode.always
}
/// 텍스트 필드에 좌우 패딩을 한 번에 추가합니다.
func addPadding(leftAmount: CGFloat = 10, rightAmount: CGFloat = 10) {
addLeftPadding(leftAmount)
addRightPadding(rightAmount)
}
}