Order is the key in Swift Interface Builder
It was two weeks for me to deal with a simple custom cell in UITableView. I thought that it would just an easy thing to drag and drop some views and then make some constraints. But there was a very tough custom cell which was sticked to its size which could't be defined by me.
Running on a mini device
These are the screenshots in runtime on a mini device and on an iPad. Hundreds of times I deleted all constraints and built up them in an other order, but nothing worked. I tried to adjust the width of the cell, but it was locked.
I began to guess, that it had been something wrong with the order at the starting point, so I tried to look through the source code of the Main.storyboard. (You know if you delete a view without unbinding its connections, you would be in trouble) Well, I tried to delete some things in source code, tried to write some code, but it became a bigger mess in it, and the app continuously crashed. One and a half weeks later I was fed up with this approach, and I start a new project with a simple custom cell. It worked. The cell expanded to the proper size depending on the width of the device. Great. Then one more step, then another. I added the StackViews first (no need to add both constrains AND alignment constraints, I didn't add specific numbers for width and high just margins ), I connect them to its parentView with CTRL+drag. I clicked equal width in its menu. It didn't mean that the view would have equal width. It was the first step to expand views proportionally. This will be my favourite tool in the future :)
After that I set the 'Equal Width Constant's Multiplier to the desired number:
The sum of these multipliers MUST equal to 1 as I experienced. Anyway you can't handle the result, because it is going to be nonsense. Finally I put the textLabels into the StackViews. And tadaaam.
The other lesson was for me that missing constraints are bad, but too much constraints even worse. You can check my Earthquake project on Github.
Next week I 'm going to write a bit about networking from my point of view.
Thanks for reading.






Megjegyzések
Megjegyzés küldése