My .plist's UIStatusBarHidden is false, so my app does not show the iOS status bar.
The UI elements that are connected to the top of a custom UIView I have, appear too high on iPhone 6/7/8 devices. This is because IB takes the status bar into account in my top constraints. (The iOS status bar is the Safe Area in my XIB.)
How do I tell IB that I don't have a status bar, so that my top UI elements appear correct for iPhone 6/7/8. I don't want to mess up they layout for iPhone X devices, which is already okay.
How things look in IB:
When running on Simulator:
By switching off the Safe Area option, it's possible to get the iPhone 6/7/8 correct (by increasing the constraint constants), but then these UI elements will be too high on iPhone X devices.
You can remove safearea at the storyboard options
Storyboard Instpector
Constraint top to root view
Related
I'm trying to display a button as per the image below. It's width and height are determined by a XIB that this button is a subview of (that's not really important information for this issue though).
The constraints are setup for the "SkipBreak" button in Interface Builder.
You can't tell from the image I've attached, but there is a transport bar located beneath the button. The alignment of the button relative to the transport bar is fine if I test on an iPad (in either portrait or landscape orientation). But if I test on an iPhone (such as the XR model) in landscape mode, the button ends up overlapping the transport bar.
Is there is a way I can set the constraints of this button so that the anchor point from the leading and bottom edges of the superview differ based on the device?
Is this what size classes are for? If so, is there a resource you can point me to in order to figure out how to do this?
Otherwise, do I have to delete the constraints programmatically, check the device type and then add the constraints?
In one of my app, i have not used navigation bar for header. I have used UIView which is of 64 height.
I just tried to design one screen app in xCode 9 to support iPhone x.
In storyboard, I have used UIView with 64 fixed height, and a label which is center to UIView
Everything is working fine in iPhone 8 and iPhone 8+, but in iPhone x, design is not looking good.
Fixed view looks small in iPhone x.
Please check below images
As i have start developing for iPhone x for other application, navigation bar gets bigger in iPhone x (around 145 px).
How can i manage design in iPhonex without navigation bar?
What you need are safe margins. Official Apple tutorial on iPhone X explains everything about them here in "Human Interface Guidelines
iOS" and here in "Designing for iPhone X".
1. Add subview to ViewController
Let’s get started by adding a subview into the view controller. This subview will be our custom navigation bar. Let’s setup auto layout accordingly.
Setting up auto layout constraints on custom navigation bar
NavBar.Height = 44
NavBar.Top = Safe Area.Top
NavBar.Leading = Safe Area.Leading
NavBar.Trailing = Safe Area.Trailing
the constraints are between the custom navigation bar and the safe area
2. Add ImageView as Background
Take an image view that display our background image. This imageview should be behind our custom view for navigation bar
Setting up auto layout constraints on image view
Image View.Top = Superview.Top
Image View.Leading = Superview.Leading
Image View.Trailing = Superview.Trailing
Image View.Bottom = NavBar.Bottom (For this drag from imageview to customview and choose last baseline constraint)
Leading and trailing constraints are all between the image view and it’s superview.
For the bottom constraint, we will set it between NavBar.Bottom and Image View.Bottom. The purpose of this is to make sure that the image view will cover up the entire custom navigation bar.
3. Final Step
A. Set clear color of custom view
B. Set image on imageview
C. Make sure the content mode of imageview is “Aspect Fill” and “Clip to Bounds” is checked.
4. Unit Test
Test this in all devices from iPhone 5 to iPhone X.
In all devices expect iPhone X our custom view with image is 64 pixel, and in iPhone X it is using the safe area also.
Behaving the same way as default navigation bar.
I have a logo in the storyboard set to a top constraint of value 28 and it works for all devices. On iPhone X device it merges with the camera bar on the top. If i increase the top constraint it affects the other devices. How do i set a constraint only for iPhone X alone?
By default Xcode provides you with a Safe Area upon project creation.
Here, I've added a UIView with the following constraints. Take note of how the constraints are pinned to the Safe Area, and not the Superview.
Running the app, you'll see that the view respects the status bar across all devices.
Hope this helps with the issue you're having...
I have a Navigation Bar in my storyboard, and set the folowing constraints:
Horizontal Space - (-16) - View Navigation Bar
Horizontal Space - (-16) - Navigation Bar View
Vertical Space - (8) - Navigation Bar - Top Layout Guide
However it appears like this:
Both in portait and Landscape oriantation.
How can i fix it so that i do not have 3 pixels of White space? (also does this on my Iphone 6plus)
I used the Inferred Size option.
It works on Iphone 4S, Iphone 5, iphone 5S, iphone 6.
My constrains seem to indicate that i have constrained the view against its Superview's margins, rather then against its actual edges. Because the margins are different between other phones and iPhone 6 Plus, my navigation bar ends up inset (because constant 16 isn't large enough).
I turned margin based constrains off in the same popup that i used to create these, but i had to remove the constraints i set first.
Steps to fix:
Click navigation bar
Click pin (the |-[]-| ) thing on the right bottom corner (3rd from the right 2nd from the left).
Click 'constrains to margins'
Source Rincewind from Apple: https://devforums.apple.com/message/1099289#1099289
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.