Auto layout Growing Space between two UIButton - uibutton

I have two UIButton having constraints from left and top at 22 point. The second one is below the first UIButton and has a constraint of 22 point from left and 22 point from the first UIButton.
My concern is I want the gap between the two UIButton should increase with different size of iPhones as per the aspect ratio.
I have a constraint of Equal width & Equal height tuned up with the multiplier on UIButton which makes the size of the UIButton grow with different sizes of iPhone but I want the gap between two UIButton to grow as well.

Related

XCode 8 - Change constraints according to orientation

Here is my problem.
I have a square image which does not fit on an iPad or iPhone app, as the screens are not square, so i decided to add a UIImageView which:
When the Phone is on Portrait position i add a constraint to the top (-20) and bottom (0) to fill the whole screen aligning X in the center and keeping the aspect ratio to keep the image square even if the screen is bigger or smaller, this means that in both sides i will "loose" part of my image, but that is fine.
When I rotate my phone to landscape position, the screen is widder,so i see a square image in the middle of the screen but a white rectangle in both sides.
I think the sollution to this is when it is on landscape position i need to remove the top and bottom constraints and add one to lead (-20) and one to trail (-20), center the image on Y axis and keep the 1:1 ratio...
But my question is: how to add a constraint to valid for one orientarion and change it to the other?
What is the best approach?
thanks
FP
You don't need to do it programmatically. I recommend you make the view fill the superview -- have one constraint each to top, bottom, left, and right. Then for the UIImageView attributes inspector in Interface Builder, set "View Mode" to Aspect Fill.
I think you have it the wrong way around.
While on portrait you should set trail and lead constraints as your height is bigger than the width, so if you set (0) for trail and lead and 1:1 ratio you are safe that it will fit beautifully. Also center it vertically in container.
On landscape, as the width is bigger than the height, you should set top and bottom (0) and ratio 1:1 and center it horizontally in container.

UIButton inside UIView goes out of bounds

I'm struggling with a problem that probably it's really stupid.
I've created an UIView and inside the UIView I've placed an UIButton and a UISwitch.
The UIView scales it's width based on the screen size keeping from left and right 45px, the UISwitch keeps it's frame size and the UIButton has its frame size changed based on the UIView frame size.
The problem is that the UIButton's text goes out of bounds for no reasons, this is the result I get:
The Blue background is the one of the UIButton and the Yellow background is the one of the UIView
I'm not able to align the text of the UIButton on top, this is what I've tried:
[_privacyButton setTitleEdgeInsets:UIEdgeInsetsMake(0,0,0,0)];
_privacyButton.titleLabel.baselineAdjustment = UIBaselineAdjustmentNone;
And also from the Storyboard I've set the vertical aligment top
Please someone help me, this UIButton is driving me crazy
You need to set constrains for the particular unbutton, i am unable to see you uiswitch, where you place it?.

Interface Builder Constraints --> UITextView flattening out when run

So I am using interface builder (which I don't often use), and I have two storyboards, one for iPhone 5+ and one for iPhone 4. The iPhone 5 one works perfectly.
However, when I run the app in an iPhone 4 or 4s, one of the UITextViews shrinks in size like it has deflated. When I use constraints, I usually put the views where I want them then do Editor -> Resolve AutoLayout Views or something, and normally the views snap into place.
Here is what it looks like in IB:
IB constraints
And this is what I get when I run the app:
The UITextView when I run the app
This is probably a really simple mistake, but I do feel like a bit of a doompf with my pancake like UITextView. Does anyone know what constraints I could add/actions I could take in order to make the UITextView the size it is in the storyboard?
I am in Xcode 6 and I am using auto layout.
Thanks in advance,
Edit Solved:
Firstly, I deleted the 3.5 inch storyboard so I only have one storyboard.
Then I selected the view in question, and fiddled around with the different iPhone sizes. Once I had put constraints that look good on all the devices, I ran it on every phone, and it worked :).
I agree with #Minestroni-Soup that you don't necessarily need to use two distinct storyboards. In any case, here's how I'd approach the problem. First, I'll ignore the horizontal direction because your problem happens in the vertical direction. If you have problems with the horizontal direction, post a new question.
Place constraints of fixed heights between vertically adjacent views in your layout, and also between the top view and the top border, and also between the bottom view and the bottom border. Then create a constraint that sets the height of one UITextView to be the same as the height of the other UITextView. That should solve your problem.
top border
constraint to set a vertical space of some amount
label 1
constraint to set a vertical space of some amount
textview 1
constraint to set a vertical space of some amount
label 2
constraint to set a vertical space of some amount
textview 1
constraint to set a vertical space of some amount
bottom border
Note that the above, alone, doesn't uniquely define the heights of the two text views but if you add a constraint that sets their heights to be the same, then all the constraints together will have a unique solution (because the labels have well-defined default heights).
I hope my explanation is clear enough.

custom view-based nstableview resizing

I have an NSView class, which draws it's contents on a CALayer. These NSView classes are held in an NSTableView which has a single column. I need to make it so the NSTableView adjusts it's size to fit the contents of the NSViews it contains, which can have variable widths, i.e. the NSTableView needs to have the same width as the widest cell. This in turn will allow the user to scroll if the cells' widths are larger than the available area.
Think of it like a multitrack audio editor, where each view is a track, but the tracks can have different lengths.
At the moment, the NSView cells seem to adjust width automatically to the size of the table column, so I can see two possibilities: One is to make it so the cell NSViews set their width, and somehow have this promulgate everywhere else. The other is to have the tableview or nstablecolumn set its width based on the maximum width. I have tried setting the NSTableColumn width and minWidth, but this doesn't seem to work (it doesn't always adjust to the correct size, if the size is big).
Any suggestions or help to make this work?
If you're using CALayer (lets call it root layer) to draw the view contents, try to create another CALayer which will be a child of the root layer (this would be the audio track). You can set the size of the child layer independently and also you will know which one is biggest.
Root layer will always be as big as the table view, as you said:"NSView cells seem to adjust width automatically to the size of the table column" - don't try to change root layer size, but child layer size.
Once you determine the widest child just change table view frame to be the same width.

Sticking a UIView to the bottom of a UICollectionView that works in 3.5 and 4 inches

I am trying to stick a UIView, containing an ADBannerView, to the bottom of my UICollectionView that works in both 3.5 and 4". My current implementation works for 4" but it gets cut off in 3.5".
3.5"
4"
Storyboard
Constraints
My constraints are essentially setup as: height = 50, space to the left, right and bottom of the screen = 0. As a test, I tried the same constraints on a separate UIViewController and it works as expected. The same constraints doesn't seem to be working in an UICollectionView.
Assuming your collectionView has leading/trailing/top/bottom constraints of 0 to its superview, which will ensure that the collectionView always occupies and is contained by the full screen.
You can then add leading/trailing/bottom constraints of 0 and height of 50 to the bannerView with respect to its superview (the collectionView). And because the collectionView will be constrained to always be fullscreen, without bleeding off, you know that the bannerView will always occupy the bottom 50 pixels of the screen too.
OR
You can add leading/trailing/bottom constraints of 0 and height of 50 to the bannerView with respect to its superview (the viewController (NOT the collectionView)) so that it really has nothing to do with the collectionView, instead it's just pinned to the bottom of the encompassing view.
Two approaches that should yield the same result.
Hope this helps!
Update
Adding an observation from my comment below:
I also now am noticing that your bannerView is a subview of a cell. This is probably not what you intend, right? (ie you dont want a banner for every cell). It should probably be a subview of the collectionView, or better yet the encompassing UIViewController...