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

前端 未结 13 1138
执念已碎
执念已碎 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:11

    This is because the BaselineOffset for the textfield got changed. In UITextFieldDidEndEditing creating an attributed text with NSBaselineOffset: 0 and using that attributedText would fix the problem.

    -(IBAction)txtFieldDidEndEditing:(UITextField *)sender {
         NSDictionary *style = @{
                                NSBaselineOffsetAttributeName: @(0)
                                };
        self.txtField.attributedText = [[NSAttributedString alloc] initWithString:self.txtField.text attributes:style];
    }
    

提交回复
热议问题