I'm struggling to get my constraints working for both ios 7 and 8 in xcode 6. My app is just a webview that should take up the whole screen and not appear under the status bar.
My problem is that it only displays correctly in either 7 or 8, but never both at once. Depending on how I adjust my horizontal constraints it's either too big for the ios7 screen and fits the 8, or too small on 8 and fits 7. Here's the issue and constrains I have set up:
*Edit: I think maybe my superview is positioned incorrectly, since my constraints are relative to the super view. I just can't figure out what would be wrong with it.
ios7 fits
too small on ios8 (green background is the parent UIView)
20point top constraint to move the view below the status bar
0 side constraint so it resizes on orientation change
0 side constraint so it resizes on orientation change
0 bottom constraint so the view isn't pushed below the bottom of the screen
I think you need to pin this webView like this
So apparently there were constraints on the parent view that I had the webview in. They did not show up in the left nav like the webview constraints did so I was not aware they were there. In the right inspector panel click on the ruler icon with the view selected and you'll see the constrains. After removing those it was just a matter of tweaking the constraints on the webview to align things properly.
Related
I am having trouble pinning the UIButton to the bottom of my UIViewController, (There is a tab bar if that helps).
Here are the constraints of the UIButton.
Originally, it all worked fine, but ever since I added iPad support to the application I have issues. on the iPad the UIButton is pinned to the bottom of the screen, directly above the tab bar. However on iPhone, there is this empty gap at the bottom.
What I Tried
Doing some research I saw that sometimes split view controller causes a grey bar, I added this line of code to resolve it and it fixed the bottom bar , but this constraint issues is still causing me a headache.
self.extendedLayoutIncludesOpaqueBars = true
iPad View Hierarchy
iPhone View Hierarchy
You have an option on Xcode to vary your constraint depending of the size of the screen.
You can create two constraints, one that works on iPad, one that works on "classic" iPhone.
Here, if I create a new constraint during the variation, I can then select on the right window which variation you want the constraint to be installed on.
There is a whole topic about that here
Remove current Constrain and Try unchecking "Constrain to margins" button.
Try setting a constraint to a View instead of a SafeArea
1- Give it a constant height for example 40
2- While setting constraints, uncheck (Constrain to margins)
3- Give it a proportional width constraint with the super view 0.8
Note1: If you don't want to give it a fixed height you can do the same step 3 but with height and not 0.8 but maybe 0.2 to less depending on your design.
Note2: You can use a scroll view, it will make it so easy for you
Ever since updating to XCode7/iOS9 something very strange seems to be happening. In my storyboard layout, the views are still the fixed 320 x 568. I was having an issue where a good chunk of the right side of the screen was being cut off when I would run the iPhone 6 simulator. So I created a new test project with storyboard and 1 view. I added a sub view, set it's background red, and made it the same size as the parent: 320 wide and set a width constraint of 320 on it. My expectation is that the red subview will scale to any size iPhone screen width.
What I get is the following:
So I logged self.view.frame.size.width and it is saying the width is 375. In the storyboard, I set the width of the red subview to 375, updated the width constraint to 375 and what do you know...it fills the width of the parent view perfectly as it should.
The problem is, I shouldnt have to do this. Why would I do my design off the screen?
Is there something Apple is trying to force here that I am not doing? I never had this issue in Xcode 6.
You're missing constraints as far as I can see.
Please add constraints as appropriate.
Recommend you add the Left and Right margins, and Top space + height.
I.e., Click the square when your "red" view is selected, then click the left, right and top sides of the box. Then click the "height" field and then "add constraints"
I'm trying to show a UITableView when a user presses the navigation bar button. My table view is built on the interface builder and I give it these constraints:
Trailing space to: superView.
Top space to: top layout guide.
Width.
Height.
(The table view should be at the top right side of the viewController's view when the user press at the button).
Now, I don't know why, but it works perfectly on iOS 8, but on iOS 7 the table is losing some pixels from the right (it slides outside from the view). I've noticed it can happen on labels too. Can anyone help me understand why?
In Xcode 6, the Layout Constraints are set against the Margin of the superview. That only works in ios 8 though. To get the old behavior, you need to select a constraint from IB, go to Attributes Inspector and see if the first or second item is set to margins.
For example:First Item: Superview.trailing Margin
Click on it and uncheck "Relative to margin". You will have to do that to all your constraints.
I have a viewController, which is configured for the iPhone5 screen size. In red rectangle is the view.
To make this view show properly in iPhone4 - I used auto layout. But when I specify constrains such as: leading edge, trailing edge, bottom space and top space (in top space I even made constraint's priority to LOW ) - the view still goes partially down the screen as if my constraints don't work.
BUT if instead of top space constraint I specify view's heigh and delete top space constraint - everything works perfectly.
Does anyone can explain it please? Thank you.
Thats because when you set up the top space constraint it will move the view by the constant you provided. iPhone 4 and iPhone 5 screen height is different but the constant remains the same so obviously it will behave differently. One way to troubleshoot your interfaces is to switching between iPhone4 and iPhone 5 on storyboard device on storyboard (first button from left to right on the bottom right corner of interface builder).
Auto-layout is all about experience in my opinion. I struggled alot with it until i learned. If you want your view to be attached to the bottom of the screen you should set the BOTTOM SPACE to 0 and specify the view's height like you did or adjust constraints for it's subviews so that the height is set dinamically according to the views inside.
I'm building an app that has a UIImageView below the UINavigationBar as the following screenshot displays.
Before I set the autoresizing constraints, I logged the bounds size, and it says the size is 320x505 which is quite reasonable because the navigation bar and the status bar takes up 64 pts.
The constraints are like this before I set them up:
And later, I've added the "inner cross" part of the constraints like below, and this time, while logging the bounds size, it gave me 320x569, which takes status bar and navigation bar into account.
I'm pretty sure that the "real" size of UIImageView does not increase, because when I load a image, it simply displays the image just fine, there's no difference, but I'm not sure why this happens.
So my question is what leads to this and how to fix it?
Thanks in advance!
The first Autosizing mode sets (among others) Fixed Top Margin & Fixed Bottom Margin & Fixed Height. Basicly, you're telling the view to have the same margins to top and to bottom but not to modify its height, which is pretty impossible, so the interface builder will give priority to the bottom fixed spring.
The second case, having Fixed Top Margin & Fixed Bottom Margin & Flexible height, stretches your images on the whole content. If you haven't unchecked the view controller's option (Extend under top bars) the full content is 568(for 4inch device, which is your case) (on ios 7 if you have that option checked the viewcontroller's view's y origin is under the navigationbar & status bar , right in the very top corner).
If you uncheck the Extend under top bar option, the viewcontroller's view will begin from 64.