0

I have an Swift app. To make padding I wrote this code:

class TextField: UITextField {

let padding = UIEdgeInsets(top: 0, left: 15, bottom: 0, right: 5)

override open func textRect(forBounds bounds: CGRect) -> CGRect {
    return UIEdgeInsetsInsetRect(bounds, padding)
}

override open func placeholderRect(forBounds bounds: CGRect) -> CGRect {
    return UIEdgeInsetsInsetRect(bounds, padding)
}

override open func editingRect(forBounds bounds: CGRect) -> CGRect {
    return UIEdgeInsetsInsetRect(bounds, padding)
}

But today I converted my project to Swift 4.2 and now I have an error:

'UIEdgeInsetsInsetRect' has been replaced by instance method 'CGRect.inset(by:)'

How can I fix it?

Ashley Mills
  • 50,474
  • 16
  • 129
  • 160
ExEr7um
  • 15
  • 4

1 Answers1

6

replace UIEdgeInsetsInsetRect(bounds, padding) by bounds.inset(by: padding)

Karthikeyan Bose
  • 1,244
  • 3
  • 17
  • 26