Height for UIViewControllers don't go beyond 10,000 - ios

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)];

Related

UIStackView, make it give up .spacing in compression resistance?

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).

Xcode : changing view size depending on screen size

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 !

UILabel number of rows with autolayout

I have a view I use in my application in many places, sometimes inside tableView and sometimes in a regular view.
Here is my view:
The main label the one left to the Heart image is limited to 3 lines, I want to know if there is a 4th line so I can show a "Read More" button.
I saw many solution here in stackoverflow but none of them is good enough mainly because most of them use preferredWidth which use a fixed number, however I don't really know what is the width of the label because in iPhone 6 the width of the label will be different from iPhone 5.
As you know I can't use the label frame because with auto layout the frame is calculated on runtime.
Someone know about a good solution? and please don't give me answer like use "ViewDidLayoutSubviews" in the VC.
I'm not presenting any code because in terms of autolayout everything work perfect.

iOS / XCode Auto Layout Woes. Easier Way?

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.

iOS Autolayout intrinsicContentSize = -1

When using autolayout, calling intrinsicContentSize seems to be the method to determine what CGSize is required to properly fit the views content.
However, this method is only supported for a limited number of existing UIViews.
Anytime that I make a custom view, even if it is something as simple as a UILabel inside of a container UIView, that containing view is unable to determine its intrinsicContentSize (returns -1).
I don't understand why the view is able to properly be displayed on the screen yet the view doesn't even know its own height...
The UILabel in a container view is a simple example but I'm dealing with slightly more complicated UIViews where there are maybe 15 views nested within eachother. In order to determine the size of the view which contains all of its subviews, I have to manually create my own intrinsicContentSize method and do very time consuming work where I have to sum up all the heights of the subviews plus add to that all of the constraints.
This process is terrible. It's very easy to miss out on a height somewhere by forgetting to add the height of one of the subviews or constraints. Also, the matter is further complicated by the fact that with dynamic subviews. For example, if the view has 2 columns of dynamic subviews, you need to manually find the height of the subviews+constraints for each column, compare these heights and return the larger of the two. Again, this is a simple example but often it's not so simple, causing many many migraines.
Back to what I was asking earlier. How can iOS display the view yet not even know how tall the view is? There must be some way to find out what that height is. Thanks for reading.
Here is an image to help visualize what I want.
Are all your subviews using auto-layout themselves? I mean that if your using auto-layout to place MyCompositeObject, is that composite object using constraints internally to place its many objects? I've found that if so, then the intrinsicContentSize will account for all the subviews, but if not, your UIView's intrinsic content size is going to end out returning something inaccurate and small.

Resources