Adjust width of UITextField to fill toolbar in landscape

被刻印的时光 ゝ 提交于 2019-12-05 07:25:36

To obtain a horizontally stretching text field, I had to manually set its frame in viewWillAppear and also when the orientation changes - I used viewWillTransitionToSize:withTransitionCoordinator::

[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext>  __nonnull context) {
    self.textField.frame = CGRectMake(0, 0, self.navigationController.navigationBar.frame.size.width - self.actionButton.width - 55, self.inputTextField.frame.size.height);
} completion:^(id<UIViewControllerTransitionCoordinatorContext>  __nonnull context) {
}];


Previous solution (no longer works for me in latest OSes):

Add this in viewDidLoad:

self.textField.autoresizingMask = UIViewAutoresizingFlexibleWidth;

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!