티스토리 뷰

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class InsetTextField: UITextField { | |
private let commonInsets = UIEdgeInsets(top: 10, left: 15, bottom: 10, right: 15) | |
private let clearButtonOffset: CGFloat = 5 | |
private let clearButtonLeftPadding: CGFloat = 5 | |
override open func textRect(forBounds bounds: CGRect) -> CGRect { | |
return bounds.inset(by: commonInsets) | |
} | |
override open func placeholderRect(forBounds bounds: CGRect) -> CGRect { | |
return bounds.inset(by: commonInsets) | |
} | |
// clearButton의 위치와 크기를 고려해 inset을 삽입 | |
override open func editingRect(forBounds bounds: CGRect) -> CGRect { | |
let clearButtonWidth = clearButtonRect(forBounds: bounds).width | |
let editingInsets = UIEdgeInsets( | |
top: commonInsets.top, | |
left: commonInsets.left, | |
bottom: commonInsets.bottom, | |
right: clearButtonWidth + clearButtonOffset + clearButtonLeftPadding | |
) | |
return bounds.inset(by: editingInsets) | |
} | |
// clearButtonOffset만큼 x축 이동 | |
override func clearButtonRect(forBounds bounds: CGRect) -> CGRect { | |
var clearButtonRect = super.clearButtonRect(forBounds: bounds) | |
clearButtonRect.origin.x -= clearButtonOffset; | |
return clearButtonRect | |
} | |
} |
'iOS > UIKit' 카테고리의 다른 글
[UIKit] TableView Cell 개수만큼 Separator line 표시 (0) | 2021.06.10 |
---|---|
[UIKit] SwiftUI Preview 사용 방법 (0) | 2021.06.10 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- reactivex
- trampoline function
- dispose
- ToolbarItem
- EnvironmentObject
- uiscrollview
- Binding
- SwiftUI
- Observable
- concurrent
- tail call
- recursive function
- UIView
- fixedsize
- Swift
- UITableView
- tableFooterView
- trampoline
- UIViewController
- FuulScreenCover
- Text.limitLine
- Disposable
- NavigationLink
- rxswift
- async
- .toolbar
- lineLimit
- DisposeBag
- UIKit
- tail-recursive
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함