How do I get a textView to expand when screen is rotated from portrait to landscape in iOS

冷暖自知 提交于 2019-12-11 12:49:53

问题


I am using the Interface Builder to create this UI:

And when it is in portrait the One and Two TextViews fill the width of the screen (which is what I want), but when I rotate it to landscape mode the TextViews do not take up the full width of the screen.

How can I get the TextViews to fill the width of the screen in landscape mode? In the Interface Builder, the "Autolayout" option is checked and if possible I would like to accomplish this with it still checked since everything else works best with it on. Any advice would be greatly appreciated since I am still fairly new to iOS programming.

Now the screenshots are posted below. If you notice text box One for example goes all the way to the edge in Portrait view, but not in Landscape view.


回答1:


If you dont want to use AutoLayout, You can use following steps.

1) In your XIB uncheck autoLayout check box.

2) Select your TextField and set autoResizeConstraints as follows.

Tyr this .... It will help you....




回答2:


You can either change the textView size programmatically when t change to landscape in the method -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration




回答3:


Select your UITextView and press the "Pin" button.

Click the left and right constraints so they turn from dotted light red to red. Enter your required distance from the superview. In my example, 5 pixels.

Remember, these two constraints are not enough to define a position of the UITextView. To do this you must either:

  • Pin the view to either the top or bottom and provide a height constraint.

  • Pin the view to both the top or bottom

  • Center the view vertically in the container

  • Align the view with some other subview that has a resolvable Y position



来源:https://stackoverflow.com/questions/19876716/how-do-i-get-a-textview-to-expand-when-screen-is-rotated-from-portrait-to-landsc

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