Indent the text in a UITextField

后端 未结 8 1301
日久生厌
日久生厌 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:18

    If you don't want to create @IBOutlet's could simply subclass (answer in Swift):

    class PaddedTextField: UITextField {
    
      override func awakeFromNib() {
          super.awakeFromNib()
    
          let spacerView = UIView(frame:CGRect(x: 0, y: 0, width: 10, height: 10))
          leftViewMode = .always
          leftView = spacerView
       }
    }
    

提交回复
热议问题