简体   繁体   中英

What is the correct way to auto expand a UIButton to the width of an interface on orientation change

I am trying to automatically expand a UIButton width to the width of an interface upon orientation change.

Does anyone have working code for this? I have tried using AutoResizing mask, but perhaps I'm not using the correct one.

There's multiple ways of doing this. In your view controller sub class overrride -willAnimateRotationToInterfaceOrientation:duration: or -willRotateToInterfaceOrientation:duration:

You could also override -viewWillLayoutSubviews and then adjust the frame depending on the orientation by querying self.interfaceOrientation .

And change the size of the button in that method, either by adjusting the constraints or changing the frame of the button.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM