When I try on iPhone 6 or higher it works fine, but for 5 it simply doesn't align correctly. I haven't set any size for the controller.
This is expected, you need to apply autolayout constrains on the subviews,
read here auto layout and here constraints
By this they will be centered on all devices or look like the way you define the constraints.
Related
I just started to learn auto layout.
I have switched off the Use Size Classes.
I make there UILabels which is shown in the image and their constraints also. I want to look similar in 4s,5s,6 and 6Plus.
But it is working fine on 4s and 5s but distorts in 6 and 6Plus.
Why this is happening and how can I resolve this.
My StoryBoard with constraints:
Output iN 5s
Output IN 6 and 6Plus
Assuming that the way labels are placed in 5s is what you are really looking for, place the constraints as follows :
Pin width of all labels equally.
Pin Height of all labels
Pin vertical position of all labels from top margin equally.
Now, as for the problem, add the constraints as follows for horizontal placement of labels :
[leading margin--0--label1--40--label2--<=20--label3--Trailing margin]
Adding the horizontal constraints should work for all sizes.
This happens because none of your constraints is hooked to the leading/trailing layout guide. What you'll want to do is to attach labels 1 & 3 to the "sides" of the view, and then attaching label 2's constraints accordingly. (I would recommend adding a center horizontally constraint, but it can be achieved by different ways).
I'm new to iOS development, so setting constraints for objects on the storyboard in Xcode has been difficult for me.
As this picture below shows, I have 3 borders for buttons I created in sketch so they are all images, each of them inside of a image view:
I tried adding constraints by pinning all three images to the left, right and below themselves but I got errors for it and it did not come out right at all on the simulators. All of the images are in aspect fill mode, and I have the view in the size of an iPhone 4 when I put the images in the storyboard. Here's an example of what it looks like in the iPhone 6 simulator without any constraints:
What are the constraints I need so that it looks okay for all iPhone and iPad sizes and looks like it does in the storyboard? And landscape mode will not be a part of this application, so that will not need to be accounted for.
You can also use button 1 equal width constraint
and button 2 equal width constraint
For more details http://www.raywenderlich.com/83129/beginning-auto-layout-tutorial-swift-part-1
Which is your requirement???
I have a series of views each containing a scrollview wrapping various subviews i.e. Collection views, Labels, imagview. I am using auto layout for the first time and some views render fine on some devices but not on others, I have attached previews of views on iPhone 4s, 5, and 6.
In particular I am not sure how the alignment of the History views appears off centre in iPhone 5 and 4 but fine in 6, and the collection view in iPhone 6 appears cut sort on the right side but not for iPhone 5,4, and lastly how the blue image with label 'Image Title' on top of the zoomable image on iPhone 4s appears to be cut short. I would of thought a error in autolayout would of been consistent across devices ?
Any input appreciated.
It looks like you're setting absolute widths on some elements. Instead you should be setting distance to the parent UIView's edges. I.e. trailing/leading space to container.
Try to give consistent constraints. Looks like you are just doing leading and top space to superview and maybe you are adding width and height constraints to avoid misplaced views. Try to think like you are doing autoresizing masks before autolayouts. Either try to keep ratio or expand with the container with trailing and bottom space constraints.
I'm using Auto Layout for an iPhone app to place a button footer bar at the bottom of the screen on both 3.5" and 4" iPhones. The bar is a UIView containing two UIButtons and a UIImageView.
I have a Vertical Space Constraint pinning the bottom space to the superview.
(Editor -> Pin -> Bottom Space to Superview)
It has an Equal relationship. Constant is 60, Standard is NO, Priority is 1000, and Placeholder is NO.
In iOS 7 it works exactly as expected. In iOS 6, it does not. The bar is not a consistent distance from the bottom when I switch between that view controller and its neighbors, and the buttons frequently do not work (they don't even highlight when I tap them). This is all in the simulator, I haven't tried hardware yet. The app is a legacy app, so all of the layout work is in xib files, not storyboards.
Do I need to do something different in iOS 6 to get Auto Layout to work? From what I read, it should be fully compatible with 6 & 7.
Some more information is needed to really get to the heart of the matter. Specifically how auto layout is being used to attach the bar to the bottom.
One thing that gets me over and over though, is remembering to set the translatesAutoResizingMasksIntoConstraints property to false on view(s) that utilize constraints.
Be sure to check the log output while debugging as that will indicate if you have any ambiguous or unsatisfiable constraints. At design time, XCode 4 IB will attempt to add any constraints that you are missing for you. XCode 5 IB will only tell you what you are missing and then at runtime try to add any missing constraints if it can.
On an iPhone 4 (or any iPhone/iPod device without the 16:9 iPhone 5 resolution) my popover looks great; not stretched at all and exactly as I intended.
However, on an iPhone 5 the popover is stretched:
And I can only assume it's because of a constraint with Auto Layout, but I can't quite figure out what is causing it.
When I select the UIView that contains all the controls in the window (and what appears to be being stretched) in Interface Builder these are the constraints it has on it (again, apologies for the height of the image, it has a lot of subviews):
I thought it was Top Space to: Superview Equals: 103 but I cannot delete that. I promote it to a user constraint, then delete it and it just reappears.
What am I doing wrong here?
In Xcode you can't delete a constraint unless there is enough constraints remaining in order for Xcode to determine the layout in Storyboard or IB, usually at minimum 2 constraint vertically/horizontally. So you will need to add a height constraint (2nd from the top) first before deleting the top space constraint:
This will give you a fixed height constraint that you want in the first place.