How can I move the clear button in a UITextField?

前端 未结 7 1596
既然无缘
既然无缘 2021-02-13 13:14

For some reason, when I add a UITextfield as a subview of the contentview of a tablecell, the clearbutton does not align with the text typed in the field, and appears a bit unde

7条回答
  •  青春惊慌失措
    2021-02-13 13:54

    Swift 4, 5

    Subclass UITextField (Working Perfectly, Tested)

    class textFieldWithCrossButtonAdjusted: UITextField {
    
        override func clearButtonRect(forBounds bounds: CGRect) -> CGRect {
    
            let originalRect = super.clearButtonRect(forBounds: bounds)
    
            //move 10 points left
    
            return originalRect.offsetBy(dx: -10, dy: 0)
        }
    }
    

提交回复
热议问题