Autolayout UILabel inside a UIView - ios

I have a UIView and inside that there is a subview which is UIView again, inside that UIView i want to add a UILabel at the centre , I am using Autolayout. I have added all the constraints to all the views , but UILabel at the centre is only visible on iPad screens, it goes missing on smaller screen, my doubt is, when its coordinates, when are calculated on resized parent UIView, turns out to be wrong or it gets squeezed so much that it becomes invisible.
Please help me on this, I am not an expert in auto layout so obvious.
Thanks
Also the outer UIView will be presented fullscreen in parent ViewController

These are my constraints
And this is my Layout in all screens
Where your label is centered and also the Black View is increasing height with aspect ratio as per the device's height

set leading,trailing,horizontal center in container and top constrain to label with it's container view.

You should align it horizontally in the container.and also no one will be able to help unless you show all the constraints.

Related

UIStackView within UIScrollView is cut off

I'm trying to use a UIStackView within a UIScrollView and I was hoping someone could point me in the right direction in creating the right constraints because I can't figure out what the problem is.
These are my constraints and ViewController structure.
So DestCont is a UIView that has a fixed height and ContentCont should take up the rest of the space, which could be (and is) larger than the screen so it should be able to scroll.
When I test it out in the simulator, I have the following problem. (Resized it so it would fit in the 2MB cap)
The green is the Root View and the black color is the ScrollView, as you can see, it cuts off the bottom portion of the ContentCont view.
EDIT
I changed the constraints, removed the fixed UIStackView height, but now, it doesn't show the bottom UIView that's in the UIStackView:
From your screenshot we know that you have set the StackView's height constraint equals to the self.view's height. Then the height is fixed(equal to one screen's height), even though its content view's height may be larger than the screen.
And UIScrollView will calculate its contentSize depending on its content, so in your case its contentSize's height will always be one screen heigt.
Delete this height constraint, let the ContentCont's content decide the height of it. Also please make sure your constrains in your ContentCont are correct.
I ended up with being fine that just my "ContentCont" UIContainerView will scroll and fixed the switching by using the following tutorial: https://spin.atomicobject.com/2015/09/02/switch-container-views/.

Center UIView with flexible Height and Width in UIView both horizontally and vertically

I want to center an UIView containing a UIImageView in an other UIView both horizontally and vertically.
So i placed all Items in Interface Builder and set Constraints for center vertically and horizontally. Then i added max height and width to avoid the inner UIView excessing the outer UIView.
But still Interface Builder tells me I need to specify X and Y Constraint for the inner UIView.
What did i do wrong?
Reason i'm needing this is, i need a UIImage which can be landscape or portrait format displayed centered in the UIView. Also there should be an Icon overlaying the UIImage in the lower right corner. So i thought best solution would be to make a UIView containing both images and place it centered in the main uiview. But it seems autolayout won't let me do this.
Can somebody hint me in the right direction please?
EDIT
For more Clarification on what i want.
I need a UIView having its Center Point fixed at exaclty one point in its superview.
How can i do this with maintaining flexible height and width and using autolayout?
Use horizontal,vertical and Leading

How to make auto layout for uiview inside uitableViewCell

i'm working for universal app; i've two uiView (top View and bottom View) top view with imageView and bottom View with uitableView; i make constrains for this tableView and the label inside the cell; but the problem on iPad; as shown on the following images
so when i put constrains for uiLbael to be at the center of the cell it's the center at all devices except iPad
the problem here for iPad uiLabel not on the center
Did you check that label has the constraint horizontally centered in container? I cannot tell from your screen shot. I see the guide lines, but this does not necessarily meant the constraint is set. Select horizontal centered in container from the align menu. If that doesn't work I'd suggest keeping the constraints and changing your size class to the iPad (Regular/Regular) and adding the constraint.

scrollview has ambiguous content width on Xcode 6

I can't understand how can I solve this auto layout problem, i have this View:
There is an UIScrollView with the elements you see in the View, but the View gives me this warning:
scrollview has ambiguous content width
I can't understand how to solve this problem, I want the the view is for the full screen size, and I want that the width will be the screen width, how I can solve it?
I observed its fix in XCode 7.3 and it is just 10 sec work. I made a video on it. Check here:
https://www.youtube.com/watch?v=yETZKqdaPiI
All you have to do, add a subview to UIScrollView with same width and height. Then select ViewController and press Reset to suggested constraint. Please check video for clear understanding.
Thanks
This is because you are not providing enough constraints so that Xcode can find Width of your scroll view.
You can see on your screen there isn't any constraints that can be satisfied to find width of scroll view.
You can do it by providing leading and trailing space of Image view which contains fix width. It also can be done with any other views. But i will prefer control which contains fix Height & Width So there isn't require to set hugging priority or Compress resistance.
Put everything in a View and that View put inside a ScrollView.
Editor -> Embed in -> View
The solutions is:
You have a UIImageView at the top. You set the width of the UIImageView to be the same as the width of the root view of the UIViewController
You set the leading and trailing space of the UIImageView to the UIScrollView to be both 0
You set the height of the UIImageView to be the height you want the image to be. And then you set the view mode of the UIImageView to be 'Aspect fit'.
I had the same problem a month ago. Add a constraint that makes the UIView inside the UIScrollView have the same size of the UIScrollView's content width. If you have multiple views inside the UIScrollView, put your UIViews inside a new UIView and make sure the new UIView has the same content width size as the UIScrollView.
Best regards,
I too faced this issue and the only way i got it solved was using the below strategy
Add a scroll view and set its constraint to fill in the screen
Add a UIview inside the scroll view lets call this view as the content view.
In this contentView, set top, bottom, left and right margins to 0 (of course from the scrollView which is the superView);
This should do it now you can follow step 3 and continue with your UI
Place your view inside the content view and add constraints to it accordingly.
Hope it helps

Have Interface Builder layout my content in a SplitViewControllers DetailView

I was mocking about with Interface Builder and the DetailView of a SplitViewController.
I have a UIImageVIew of size 700px by 700px in the detailView and nothing else, I would like it to always position itself in the center. Because it is 700x700 it should fit in both portrait and landscape. However, there is also a UIToolBar governing the top 44 pixels. If I use IB and set the UIImageViews contentMode to center and the detailViews contentMode to center, the UIImageView is positioned so that it covers a few pixels of the toolbar. (but in the center non the less)
I have tried anchoring the UIImageView to the bottom, but it still positions itself in the center and the layout still covers the toolbar.
How would I go about doing the layout as "UIImageView:Deduct the space the toolbar takes up and position your self in the center of the remaining view" ?
Hope someone can help, the IB layout engine is a bit heavy to figure out by trial and error:)
Thank you in advance.
Add a UIView that goes from the bottom of the toolbar to the bottom of the entire view and stretches completely left to right. Set its Struts and Springs (cmd-3) so that it resizes vertically and horizontally and is attached to all 4 sides. Then put your UIImageView inside THAT view with all of the same centering you've already done. That will change the UIImageView's frame of reference so when it is trying to be in the center, it'll be in the center of that view which doesn't include the toolbar. Let me know if this makes sense.

Resources