IOS/Storyboard/Autolayout: Center round button under horizontal bar - ios

This should be incredibly simple but somehow has proven incredibly complicated for me with auto layout.
I have a horizontal bar shaped button. I want to center a round information icon below it. Auto layout keeps trying to stretch the round button into an oval and is not centering it from left to right as in the following:
The above is the result of the following constraints that should work but don't.
Can anyone please tell me the correct constraints to add to accomplish this simple task.
Thank you.

If the image is being stretched, then set its contentMode to be aspectFit or aspectFill.
Once that is done, you can add a constraint to the image so that it and the login button share vertical centers.

Can you see this yellow box showing in your view? It's showing a warning that means the view which is selected right now should be placed here according to the defined constraints. I guess the constraints of this view are conflicting with other views. Try to resolve this warning by adding "suggested" constraints or by fixing misplacement. I hope it'll work, if not then give me your code I'll resolve that issue for you.

Related

Align edge of element to center of superview in xCode/swift

I found another stackoverflow post asking about essentially the exact same thing I am trying to solve (iOS Autolayout how to stretch 2 button horizontally), however I am still having issues figuring out how to go about aligning the edge of my object to the center of the superview. I need my two buttons to be aligned side-by-side just as in the example in the post I linked, but I cannot figure out how to reference the center of the superview to set my alignment to it, like is shown in the screenshots. Could someone provide a little more insight as to how to achieve the result mentioned in the linked post? Thank you so much.
One way is to set the pin the left button to the left edge. Right button to the right edge, Pin the left side of the right button to the right side of the left button. Then set their widths equal. This is the easiest way for me if I'm using storyboard.
Make sure the constraint between the two buttons has a constant of 0 or however much space you want between them.
If you take a look at this screenshot it will click that button when its red or yellow it will tell you what constraints you are missing on a button.
If a view is misplaced simply hit the view and press cmd+option+"=" and it will give you a preview based on the constraints you've placed on it.

Why do autolayout constraints in Xcode cause my subview to disappear off screen?

I'm trying to figure out how to use autolayout, and there seems to be a lack of info about it on the internet. I placed a view within my view controller with three buttons inside it. Before I place any constraints, the buttons show up on the preview. However, as soon as I make ANY constraints, the whole sub view completely stops showing up in the preview. I made a constraint to center vertically, and then one to place it 25 pixels from the left edge. It should know exactly where to place it, but still nothing shows up.
Any ideas on why constraints cause my buttons to not show up?
With Autolayouts the constraints should be as clear as possible. You can try by adding size constraints as well as fix(right, top or bottom) constraints if necessary.
When you don't use auto-layout it positions everything manually. When you enable auto-layout it switches this behaviour off so you have an unconstrained object, which is why it dissappeared.
Turns out I didn't have constraints on the size of the sub view, so it didn't know how to center it. I didn't think I needed that because I thought it would default to what it's already at.

Size-classes and constraints with buttons

I hope someone can help here as I've been reading and watching a lot about size classes as I've just started work on first app using size classes.I thought I'd got the idea but having a slight issue.
I've got a view with 10 buttons in it. I want the buttons to re-size to fill the desired screen but as you can see from the screenshot below all I'm left with is loads of white space on the bigger views?
I've set constraints to the view and to each other so I though Aspect Ratio should solve it....No, all I get them is one huge buttons and the rest stay the same!
I've researched a lot so any guidance would be greatly appreciated.
Please see this image of the issue.
Thanks
Pin the top of the top button to its superview.
Pin the bottom of the bottom button to its superview.
Assign a fixed vertical space between each button.
Select all the buttons and specify "Equal Height."
This should take care of your vertical constraints, and the button heights will equally expand or contract, depending on the screen height.

iOS layouts for a beginner

So I consider myself a relatively bright person, not genius but not moron but I cannot seem to understand even the basic layout principles of iOS and wondered if someone may be able to point me to something that would help.
Specifically I am working on a storyboard on a view with an ImageView and a CollectionView. I have tried to get the image as a header but every single tutorial that I have tried doesn't seem to work (a problem that I have seen recurring with iOS development).
So I put the imageview with constraints at the top, left and right so that it sits in the middle at the top. The problem that I have is that when I put the collection view underneath the image, it either dissappears (most of the time if I add ANY constraints) or it sits over the top of or beneath (as in behind) the ImageView. Is there any concept of relative constraints? Why is this so hard in iOS? IS there a working tutorial that doesn't require me hand coding the layouts? Is it better for me just to hand code the layouts as the storyboard is the biggest time sink I've ever seen?
Your thoughts and help will be hugely appreciated.
It should just work. Try this (I tried and both the imageView and collection view show):
What I did:
Add UIImageView with top, left and right constraints;
Add height constraint to image view;
Add collection view with bottom, left and right constraints;
Add top constraint to collection view relative to uiimageview top + uiimageview height.
Result:

Top Space Constraint on UIView but not UIImag

I'm having a heck of a time with using some of these constraints. I'm simply trying to add a UIView in the IB so that I can inject other views into as needed. However, I can not get the positioning right. No matter how many Constraints I add or remove I cannot seem to remove the 'Top Space to: Superview'. I'm simply trying to pin the UIView to the bottom and have it float up for the different screen sizes. This 'Top Space' is forcing the UIView off the screen and I can't seem to remove it nor de-prioritize it.
UIView Constraints (doesn't work) - sorry can't post images yet
http://i1322.photobucket.com/albums/u574/dneely79/uiview-constraints_zpscae66ed9.png
On another note though I can remove the UIView and add a UIImageView and I can get this to work. So, for now I'm actually injecting my views into this element instead of a UIView. Its working, just feels dirty.
UIImageView Constraints (Works)
http://i1322.photobucket.com/albums/u574/dneely79/uiimageview-constraints_zps726da545.png
Anyone else have any thoughts on how to overcome this? Its been driving me mad and doesn't seem to make much sense to me.
I've already tried this help link (though trying to anchor bottom and not top)
Xcode 4 and Interface Builder: Editing Vertical Spacing Constraint (Anchor Top, not Bottom)
Thanks ahead of time for any help or advice on this matter.
This was a semi-goofy mistake on my part based on the defaults that IB gives you. I went back and better analyzed my own pictures.
After noticing a height set on the UIImageView and not UIView, I added a height and was able to successfully delete the Top Space.

Resources