I've a stack view inside scroll view as shown in the image below. I want to align it vertically in center. It doesn't align vertically in center on iPhone 5S, it works fine on iPhone 11 Pro Max. I've seen this solution https://mcmap.net/q/495838/-center-uiview-vertically-in-scroll-view-when-its-dynamic-labels-are-small-enough-but-align-it-to-the-top-once-they-are-not and my implementation is exactly same. How do I fix it so that i aligns vertically in center on all devices?
How to align stack view vertically in center inside scroll view?
Asked Answered
"except that I'm not able to do following: change contentView height constraint to Priority: 250" Why are you not able to do that? Is it because you have no height constraint? It looks to me like you do have one. –
Cis
I've followed the solution again, I can see that he has set contentView equal height to ScrollView, I always set it to outer view that's why I missed it, Anyways I've set the height for contentView and changed it's priority to 250 but I'm still having same issue. Stack view doesn't align vertically in center on iPhone 5S. I've also update screenshot. –
Proconsulate
@Proconsulate = A little tough to know what you need to do - but most likely, since you have labels / text fields? / image views / etc embedded in views in the stack view, you need to make some Content Hugging Priority adjustments. I've tried to duplicate your layout here: github.com/DonMag/CenteredScroll ... the results: i.sstatic.net/fCItN.jpg –
Displode
@Displode thanks for taking so much effort to create the project. I've checked your project and guess what, I found the issue. the culprit is Content Layout Guides. If it is disabled then it doesn't center, if it's enabled then it does. I've checked both yours and my project and similar behaviour. So it all comes down to "Content Layout Guides". How do we go from here? –
Proconsulate
@Proconsulate - hmmm... I just removed the Content and Frame Layout Guides from the second tab's VC and it centers as expected. Didn't even have to re-add constraints -- IB automatically changed them to Superview. I updated my GitHub repo. –
Displode
Thanks, Just realised that the issue is only on simulator and not on device. Not sure why? –
Proconsulate
© 2022 - 2024 — McMap. All rights reserved.