Search code examples
iosautolayout

Auto-Layout vertical spacing issue


I'm having some issues with auto-layout where it would show different spacing in IB than in runtime.

Here's the screenshot of IB:

IB screehsot

As you can see, the big numbers don't have any padding at the top and bottom.

But when run, it looks like this:

runtime screenshot

Am I missing something?

BTW, I come from Android dev, and looking at all those constraints I feel like I'm either missing a simpler solution or iOS UI dev is a real pain compared to Android.


Solution

  • "I'm either missing a simpler solution or iOS UI dev is a real pain compared to Android"

    You're missing a simpler solution. Auto-layout can be frustrating, until you get the hang of it. After that, it makes things sooooo much easier than it used to be.

    Here is a version of your table cell, where the spacing stays consistent between IB and runtime. And, it uses UITableViewAutomaticDimension

    enter image description here

    As you can see, it's much simpler than what you had. If you tell me if you're using Objective-C or Swift (2.2? 3.0?) Xcode 7 or 8, I'll be happy to make the files available...