Say you have a vertical stack view, it has three items, and the spacing is set to 50. It turns out to be 4 inches tall.
It turns out it's going to compress to about 3 inches (say, when the keyboard comes up - whatever).
You set CCRP to a low value - you indeed want the stack view to compress.
Oddly in all our experimentation, it seems that it will not collapse the "50" no matter what.
It seems that no matter what you do, it will take every other possible step, crushing the three items etc - but it will never give up the spacing.
Am I in error?
is there perhaps some separate way to set the CCRP "for the spacings" as such?
Do you have to flag it somehow that you want it to give up spacings?
BTW I'm totally, completely familiar with the other approaches to do this. The question is how to make a UIStackView change it's mind about the spacings seemingly being immutable.
You're correct. The spacing doesn't change. You will want to add a spacer view to accomplish what you're looking for (the last paragraph of your post makes it sound like you're familiar with this approach).
Related
I am making something that is longer than 10,000 height for a ScrollView and ViewController. I've made it 10,000 but when I go beyond 10,000 it gives an error, is there a way to go beyond 10,000?
I have used many apps that go beyond the number 10,000 but when I try to create something beyond 10,000 it would give me an error saying
"Interface Builder does not support UIView sizes larger than 10,000 by
10,000."
This would help me a lot, if it would be possible, but I have seen a lot of apps that have a scrollView longer than 10,000. Need help!
After this annoying bug appeared in my project, I've been finally able to fix it following these steps:
(I had three views with a height of 24.142.523, one within another)
First, I set a height constraint of 30 for the three views (starting from the more nested).
Second I remove that constraints in the reverse order.
After this all "Interface Builder does not support UIView sizes larger than 10,000 by 10,000." errors disappeared.
Regards!
EDIT:
I've just noticed a weird thing. If I try to put a label with no text within a Stackview it sets a size of thousands, however if I set a text with a white space or a random string it works fine.
I don't know why you want to make 'UIScrollView' so big? I hope it's because of settings the elements in the UIScrollView.
Do the following things to solve:
Make UIScrollView as long as you have to! (Ignore error)
Set all you your elements in it.
Once all is done, resize the UIScrollView to fit into
UIStoryBoard or under the specific area in which you need to display
UIScrollView.
Hope this helps!
If you want to make a big subview that contained in scrollView, like a map, you'd better to do it programmatically, and better to split your 10000 size map into smaller pieces like 512 x 512, while user scrolling the map, load each piece lazily.
(And if you persist to do it in one view, you can do it as you like programmatically w/o that warning, though it's not recommended.)
But if you want to make the scrollview large enough to contain sth else, then you'r in wrong direction to solve the problem, you should modify scrollView's contentSize instead of frame:
[yourScrollView setContentSize:CGSizeMake(10000.f, 10000.f)];
I would like to change view size depending on the screen size of the device.
For example, the view should not have the same size on iphone 4s and iphone 6.
The best way would be to use size class, but iphone 4s and iphone 6 are in the same.
Is there a way to add custom size class in order to do that ?
Or should I set auto-layout constraint programmaticaly depending on screen size ?
Thanks
At this point in time you really only have one solution, and it is using constraints.
Constraints have been existing for a long time now and should be used in all iOS projects. Never EVER change view sizes using their frames. Always adjust the constraint instead.
You can achieve pretty much anything using constraints. There are many tutorials / stack posts about it, you'll be able to look it up.
From what I understand here, you want your view to be bigger on bigger screens, and smaller on smaller screens. Without any other information i can only show you a very trivial example.
Add 4 constraints in storyboard (or in code, but it's just easier in storyboard I believe) from your resizing view to another view. Those four constraints should be Top, Bottom, Leading and Trailing (Up, Down, Left and Right).
Each constraint will basically say "my view should be X units from its superview, on that side".
If you go in the constraints attributes you can configure different things, like "I want my left side to be X units from the right side of that other view".
I suggest you mess around with colored empty views and see how they work, and if you can, have a more experienced programmer answer your questions on the side, because constraints, as simple as they are, are quite confusing at first. It took me about 2 months to be what i consider comfortable with it, and I'm a full time developer.
I can answer a couple more questions here if you want, but I'm pretty sure we'll be off topic really fast !
Have fun using constraints, they're great !
I'm wondering if xCode auto layout / constraints are really as frustrating as I think, or am I just not understanding them. For example, I started with this basic label in the view controller:
Fair enough. A box with text that has equal margins on the left/right and a smaller top margin. Now when I run any size device, that gets skewed/cut off from the device view. So right away for some reason Xcode thinks that despite me putting the entire label in the view controller, it things it should display halfway off the screen. Don't get it but okay, so I went ahead and added auto layout constraits to the right, left and top margins. The result is:
So it centered it, which is nice, but now it just ignores the fact that I made the width larger and it just shrinks it down anyways? For something so simple this seems to be very...unreliable. I then added the "aspect ratio" constraint and it seemed to look fine in all of the devices...finally!
I curiously also simply tried to get rid of all those, and simply add the "aspect ratio" constraint and the "horizontal center in container" constraint. On the main storyboard preview (not the simulator) it looked like this:
Not what I'm looking for, as it's not stretched downward like I want, they shrunk it again. However...when actually running it in the simulator...it looks perfect, the way I want it to in the first picture of the view controller.
Why the preview and simulator differed, I suppose (from reading other questions) it's because there were a few warnings after I added these. One was that the horizontal and vertical positions are one initially and will be different at run time. But when I ran it, it definitely held the initial ones and not the ones they said it would be at run time. It also told me that vertical position was ambiguous...well yeah I only set a center and aspect ratio...pretty obvious and not sure how I'd even solve that error. It solves it when I delete the horizontal center...but now it's not centered which is a step back from what I wanted.
Long story short, how do I deal with this. My previews and simulations aren't accurate with each other even for the simplest auto layout specifics. Apps nowadays are so complicated and on every device they scale and work beautifully, and this seems to not agree with even just one label.
Does anybody have any good articles, advice, or anything that would help me? This auto layout stuff seems to be so picky and that's really all I know so I have to deal with it. And don't even get me started on why the text doesn't scale with the label...why would I want the text on an iphone 4 to be the same on an ipad even when my label is increasing in size with the device?
A lot to go through, but it's just very frustrating and I can't see myself doing much else before I try to understand these basics. Thank you and much appreciated.
I think you have to understand constraints first...without that you always made things frustrating....For understand the constraints you can check this links
http://www.raywenderlich.com/50317/beginning-auto-layout-tutorial-in-ios-7-part-1
http://mathewsanders.com/designing-adaptive-layouts-for-iphone-6-plus/
It takes a bit of experience to get used to it, but once you get it, you get it for good and it's very easy.
Basically the rule of thumb is don't trust exactly what you see in storyboard when it comes to the size of the actual object. Say you have a UIView centered horizontally and vertically in the main view. True it will try to keep the size of that UIView but center it in any size device, but I would never just leave it at that. I would either:
Add width and height constraints
Add a width/height constraint and an aspect ratio constraint
Add a width constraint and top and bottom constraints
Add a height constraint and leading and trailing constraints
Add top, bottom, leading, and trailing constraints
In other words, the exact size of the object should always be determined via the constraints, and not by the UIView itself. This gets away from the finicky behavior and also ensures that it's displayed on any device exactly the way you intend it to.
I designed something on table view cell and then i clicked "Add missing constraints"
it looks like this
But when i run it on iphone 5s simulator, it looks like this
It doesn't fit the layout and overflows
How can i make it looks fit on all iphone 4-5-6 ?
Xcode does not know how to set up constraints that will cause a UI to "look good". Looking good is a subjective human judgment and computers can't do that.
"Add Missing Constraints" will just make some rough guesses, as best as the Xcode engineers were able to generate algorithmically. They are guaranteed to be sufficient to resolve ambiguities in the current set of constraints, but not guaranteed to do anything especially smart for keeping a UI looking good.
Auto layout requires you, the developer, to do thoughtful, careful consideration of how the UI should look under various circumstances. You then have to set up the constraints to achieve that. You can't just go on autopilot. You have to do the work.
If, after setting up the constraints, you still get results which are wrong, you need to show the specific constraints you set up, how you expected the UI to be laid out in various circumstances, what behavior you actually got, and how that differs from what you wanted/expected.
For example, you say about the screenshots, "it doesn't fit" and "[it] overflows". Well, which elements of your UI would you want to have moved and/or resized, and how, to get it to fit and not overflow? Do you want the image to be made smaller? Do you want the "Feedback" and "Download" buttons and the stars to get closer together? Would you want any of those to be truncated or clipped if the overall width is just too narrow to fit all of them? Etc.
I have three different alternatives to design a view, at least three that I could think of / understand from different blog posts and SO questions. The layout is pretty simple, some labels and textfields to provide a login. The thing is that it should adapt to any device screen (iPhones portrait for now to limit scope).
Each one of the three alternatives seem to have pros and cons, but I want to understand which one (if any) is the proper way in which we are supposed to design with adaptative layout, size classes and universal storyboards in mind.
Please, don't hesitate to point me wrong!
1.- Design on Any W | Any H size class, and once I'm happy with the default design move on to specific situations:
The issue here is that there isn't a size class that allows me to specify a constraint only for 3.5inch devices (all cases I tried affect none or several). Therefore, I don't know how to properly define a specific constraint that overrides the default one in this unique case.
2.- Same as before, design on Any W | Any H but using smaller gaps between elements.
It looks as good as it gets in smaller devices, but a whole lot of space is lost in bigger ones as the constraints don't adapt. Maybe constraints should be overridden in this case, which would be the inverse case as the previous point.
3.- Use a subview hierarchy to distribute the elements.
Embedding elements in subviews inside other subviews I managed to have a dynamic layout that adapts to the height of the screen, but it doesn't look right at all in bigger screens. The subviews are expected to take up the same height, but I'm not sure this is quite correct.
i think it really depends what you want, its hard for us to tell you what your app should be like, although i would think the last case is what you would most likely want (in general, for a login page like this i would choose number 2), i think it can be achieved without using subviews though, try setting each textfield to having a vertical center, and set the multiplier to a value that puts it in the right place, then it should stick proportionally where its supposed to be