[예제] TextField

J.Noma·2022년 1월 25일
0

iOS : 뽑아쓰는 예제

목록 보기
11/12

TextField
Text Field

inset 넣기

class CenterAlignedTextField: UITextField {
    
    enum LayoutAttribute {
        static let inset = UIEdgeInsets(top: 5, left: 5, bottom: 5, right: 5)
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        configure()
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }
    
    override open func textRect(forBounds bounds: CGRect) -> CGRect {
        return bounds.inset(by: LayoutAttribute.inset)
    }
    
    override open func placeholderRect(forBounds bounds: CGRect) -> CGRect {
        return bounds.inset(by: LayoutAttribute.inset)
    }
    
    override open func editingRect(forBounds bounds: CGRect) -> CGRect {
        return bounds.inset(by: LayoutAttribute.inset)
    }
    
    private func configure() {
        layer.borderColor = UIColor.systemGray4.cgColor
        layer.borderWidth = 1
        layer.cornerRadius = 5
        font = .preferredFont(forTextStyle: .callout)
        adjustsFontForContentSizeCategory = true
    }
}
profile
노션으로 이사갑니다 https://tungsten-run-778.notion.site/Study-Archive-98e51c3793684d428070695d5722d1fe

0개의 댓글