SkyFloatingLabelTextField icon indicating copy to clipboard operation
SkyFloatingLabelTextField copied to clipboard

rightView and leftView are ignored in editingRectForBounds

Open amarcadet opened this issue 8 years ago • 1 comments

The rightView frame is ignored in editingRectForBounds, textRectForBounds and so on.

See below:

I have implemented the behavior in a subclass, hope it will help you. In my case I didn't have the need for a leftView, so you might need to take care of updating the x as well. Also I don't know if you wouldn't have conflict with your icon property or you might handle it using leftView.

//
@IBDesignable class SearchFilterFormTextField: SkyFloatingLabelTextField {
    //
    var shouldDisplayRightView: Bool {
        return self.rightViewMode == .Always
            || (self.editing && self.rightViewMode == .WhileEditing)
            || (!self.editing && self.rightViewMode == .UnlessEditing)
    }

    //
    override func rightViewRectForBounds(bounds: CGRect) -> CGRect {
        if self.shouldDisplayRightView {
            return super.rightViewRectForBounds(bounds)
        } else {
            return CGRect.zero
        }
    }

    //
    override func textRectForBounds(bounds: CGRect) -> CGRect {
        var rect = super.textRectForBounds(bounds)
        let rightRect = self.rightViewRectForBounds(bounds)
        rect.size.width -= rightRect.size.width
        return rect
    }

    //
    override func editingRectForBounds(bounds: CGRect) -> CGRect {
        var rect = super.editingRectForBounds(bounds)
        let rightRect = self.rightViewRectForBounds(bounds)
        rect.size.width -= rightRect.size.width
        return rect
    }

    //
    override func placeholderRectForBounds(bounds: CGRect) -> CGRect {
        var rect = super.placeholderRectForBounds(bounds)
        let rightRect = self.rightViewRectForBounds(bounds)
        rect.size.width -= rightRect.size.width
        return rect
    }

    //
    override func titleLabelRectForBounds(bounds: CGRect, editing: Bool) -> CGRect {
        var rect = super.titleLabelRectForBounds(bounds, editing: editing)
        let rightRect = self.rightViewRectForBounds(bounds)
        rect.size.width -= rightRect.size.width
        return rect
    }
}

amarcadet avatar May 24 '16 13:05 amarcadet

This looks like it could fix #40.

@gergelyorosz did you ever get time to look into this like you mentioned in #40? If not, I'm happy to work on a PR for this :)

ky1ejs avatar Aug 24 '16 22:08 ky1ejs