从 iOS 7.1 开始,更改字体大小和调用sizeToFit
无法按预期工作。文本将不会绘制在正确的位置,将被剪切。当第一个响应者到达时,文本会转到正确的位置UITextField
。调用resignFirstResponder
会使其再次失败。
有没有人有解决方法?
- (void)viewDidLoad
{
[super viewDidLoad];
UITextField *textField = [[UITextField alloc] init];
textField.text = @"This is a test";
textField.backgroundColor = [UIColor redColor];
[textField sizeToFit]; // Calling this will make the second sizeToFit to fail
textField.font = [textField.font fontWithSize:textField.font.pointSize * 3];
[textField sizeToFit];
textField.center = CGPointMake(self.view.frame.size.width / 2.0, self.view.frame.size.height / 2.0);
textField.delegate = self;
[self.view addSubview:textField];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}