UITextFieldに余白がなくなる件

デザイン的にborderStyleをnoneだとかlineにするときに余白がなくなって辛い…

ので、CustomなUITextFieldを作ることになったのが、これ。

@IBDesignable
class MATextField: UITextField {
    
    @IBInspectable var paddingTop: CGFloat = 0
    @IBInspectable var paddingLeft: CGFloat = 0
    @IBInspectable var paddingRight: CGFloat = 0
    @IBInspectable var paddingBottom: CGFloat = 0
    override func textRect(forBounds bounds: CGRect) -> CGRect {
        return UIEdgeInsetsInsetRect(bounds, UIEdgeInsetsMake(paddingTop, paddingLeft, paddingRight, paddingBottom))
    }
    
    override func editingRect(forBounds bounds: CGRect) -> CGRect {
        return UIEdgeInsetsInsetRect(bounds, UIEdgeInsetsMake(paddingTop, paddingLeft, paddingRight, paddingBottom))
    }
    
    override func placeholderRect(forBounds bounds: CGRect) -> CGRect {
        return UIEdgeInsetsInsetRect(bounds, UIEdgeInsetsMake(paddingTop, paddingLeft, paddingRight, paddingBottom))
    }
}

Storyboardでパラメータ変更してもStoryboard上で確認出来ないけど☆(ゝω・)vキャピ

仕事iOS, swift

Posted by tkymgr