Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting custom rightView on TextField causes strange scroll behaviour #18

Closed
RaoulNL opened this issue Jun 11, 2018 · 1 comment
Closed
Assignees
Labels

Comments

@RaoulNL
Copy link

RaoulNL commented Jun 11, 2018

Hi,

Awesome component!

Question though; I want to set a custom rightView on one of my TextFields, but when I do so the rightView also scrolls down when the custom errorMessage, displayed below the line, is animated.
Note: I use the component in a swift project using a bridging header.

My code to set the custom rightView:
let eyeButton = UIButton(type: .custom)
eyeButton.setImage(UIImage(named: "icon_eye"), for: .normal)
eyeButton.imageEdgeInsets = UIEdgeInsetsMake(0, -16, 0, 0)
eyeButton.frame = CGRect(x: CGFloat(passwordTextField.frame.size.width - 16), y:(passwordTextField.frame.size.height - 16) / 2, width: CGFloat(16), height: CGFloat(16))
eyeButton.addTarget(self, action: #selector(self.togglePassword), for: .touchUpInside)
passwordTextField.rightViewMode = UITextFieldViewMode.always
passwordTextField.rightView = eyeButton

The setup of the MFTextField itself it pretty straightforward, using properties like underlineColor, placeholderFont etc.
Can someone verify this behaviour?

Cheers, Raoul.

@RaoulNL
Copy link
Author

RaoulNL commented Jun 13, 2018

The issue I described can be solved with a small adjustment to the MFTextField.m file.
Here's the code:

- (CGRect)rightViewRectForBounds:(CGRect)bounds
{
CGRect rightViewRect = [super rightViewRectForBounds:bounds];
rightViewRect.origin.y = CGRectGetMidY(_textRect) - (rightViewRect.size.height / 2.0f);

return rightViewRect;
}

Obviously, this could also be applied to the leftView.

@stephsharp stephsharp self-assigned this Jun 24, 2018
@stephsharp stephsharp added the bug label Jun 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants