This question already has answers here:
Can I adjust a CGRect with a UIEdgeInsets?
(3个答案)
去年关门了。
我有一个快速的应用程序。为了填充,我编写了以下代码:
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)
}

但今天我将我的项目转换为Swift 4.2,现在我有一个错误:
“UIEdgeInsetsInsetRect”已替换为实例方法“CGRect.inset(by:)”
我怎样才能修好它?

最佳答案

UIEdgeInsetsInsetRect(bounds, padding)替换为bounds.inset(by: padding)

关于swift - 如何使UITextField填充,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52534943/

10-13 04:04