Dimitre Bogdanov
Dimitre Bogdanov

Reputation: 396

ios autolayout issue on smaller screen

Originally I am working off of a view of size 4.7 inches in my storyboard and laying out everything from there, however I'm running an issue when running the app on a smaller screen.

The view in question is a view with a scrollview inside of it and a bunch of labels and text fields inside that. When running on the iPhone 4s for example, or even the 5, the scrollview appeared to be pinned at the bottom and I was wondering why, I had tried playing around with insets and offsets but nothing worked.

Looking at my storyboard, when I switched the fixed size of the view to 3.5 inches, it looked like all my top elements were outside of the view altogether.

I'm not exactly sure how to go about this situation.

Any help would be appreciated.

Upvotes: 0

Views: 248

Answers (1)

tnek316
tnek316

Reputation: 640

Can't help too much without more information but it sounds like you don't have constraints set properly. You should have constraints set for the scrollview to match the views size and be centered as well the labels have constraints to the scrollview, other wise when the screen sizes change there will be issues. When working in storyboards you should try using the inferred size instead of a certain screen size, that way you don't try to design the interface for a certain screen size.

In code you could do something like this to set proper constraints

scrollView.frame = view.frame //Or I could set the height, width, center contraints
label.translatesAutoresizingMaskIntoConstraints = false
label.centerXAnchor.constraintEqualToAnchor(scrollView.centerXAnchor).active = true

I would try to help with the storyboards but I would need a little more info. I tend to do my constraints in code.

Upvotes: 1

Related Questions