Text in UITextField moves up after editing (center while editing)

前端 未结 13 1111
执念已碎
执念已碎 2020-12-01 03:14

I have a strange problem. I have an UITextField in which the user should write the amount of something, so the field is called \"amountField\". Everything looks fine, when t

13条回答
  •  生来不讨喜
    2020-12-01 04:14

    I wasn't able to change the font file, so when I solved this I saved the original UITextField's frame in a property and applied the following code:

    - (void)textFieldDidBeginEditing:(UITextField *)textField
    {
        textField.frame = self.usernameFrame;
    }
    
    - (void)textFieldDidEndEditing:(UITextField *)textField
    {
        textField.frame = CGRectOffset(self.usernameFrame, 0, 1);
    }
    

    It's a bit hacky, but it gets the job done.

提交回复
热议问题