Indent the text in a UITextField

后端 未结 8 1317
日久生厌
日久生厌 2020-12-07 08:35

My question is as simple as the title, but here\'s a little more:

I have a UITextField, on which I\'ve set the background image. The problem is that the text hugs so

8条回答
  •  孤城傲影
    2020-12-07 09:07

    I turned this into a nice little extension for use inside Storyboards:

    public extension UITextField {
        @IBInspectable public var leftSpacer:CGFloat {
            get {
                return leftView?.frame.size.width ?? 0
            } set {
                leftViewMode = .Always
                leftView = UIView(frame: CGRect(x: 0, y: 0, width: newValue, height: frame.size.height))
            }
        }
    }
    

提交回复
热议问题