Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make ScrollView width = to device screen width?

I am making an app that has a (child) View inside a Scroll View. I understand I have to explicitly set the child View's width since the Scroll View won't provide that information to the child, but how can I make this child View's width auto-adjust based on the width of the device?

For example, in the below I've set the width to 380 which centers the "Quotes" in iPhone 6, but makes them slightly right of center in iPhone 5.

screenshot

like image 683
vk2015 Avatar asked Jul 13 '15 16:07

vk2015


1 Answers

You can use auto layout to set the width of your subView equal to your main View by performing a control drag from your subView to your main View like this:

enter image description here

Then select "Equal Widths" from the popup

enter image description here

like image 192
rmp Avatar answered Oct 02 '22 19:10

rmp