开发者

Moving a textfield horizontally within view

开发者 https://www.devze.com 2023-01-06 05:15 出处:网络
I have multiple textfields in a view (not a scrollview); 2 in particular are side by side, all are created in IB.

I have multiple textfields in a view (not a scrollview); 2 in particular are side by side, all are created in IB.

I use the same .xib for more than 1 entry screen. All textfields appear above the keyboard so keyboard covering these fields is NOT a problem.

On some screens I only need one of the two side-by-side textfields so I hide the other.

For aesthetic purposes only, on those screens where one field is hidden, I want to move the other textfield to the right or to the left in order to center that remaining textfield, keeping all of the other textfields on the screen stationery.

The .center property to get and move the center of the textfie开发者_StackOverflow中文版ld, doesn't seem to work with uitextfield.

Any ideas please


.center should work on all UIView subclasses, including UITextField.
For example:

leftTextField.center = CGPointMake(100, 120);

Or:

leftTextField.center = CGPointMake(containingView.bounds.size.width / 2, containingView.bounds.size.height / 2);

You might also change the location by updating the .frame...

Could you post some code that you use and doesn't do the work?

EDIT: Modified the second code sample...

0

精彩评论

暂无评论...
验证码 换一张
取 消