My app uses a navigation controller. On this particular screen the navigation bar is transparent, to take advantage of images. The image view is set via the story board. The constraints are:
Height 300
Top space to Top Layout Guide -64 (To make the image appear behind the navigation bar)
Equal width to container
This renders correctly on all devices up to iPhone 8 plus however on the iPhone X it does not. Another issue is; A view I create programatically using X and Y coordinates also shows in the wrong position on iPhone X. Again this works on all devices up to 8 Plus. Below is how I'm create the "card" view:
let card = UIView(frame: CGRect(x:10, y:245, width: viewSize-20, height:80))
Please can you advise how to handle both of these issues on iPhone X without affecting other devices?
Screenshot of issue(s):
Thanks in advance.
Related
A header component in my app is just a simple UIView with a title and a bottom border and the height of it is 64, it looks like this on any other devices except for iPhone X:
However, on an iPhone X device, it looks like this:
How do I automatically make the height of the header larger when the app is running on an iPhone X device but remain 64 on any other devices like this?
A couple of points to help you get into the right direction:
Do you have a solid reason NOT to use a UINavigationController?
This would give you a navigation bar + navigation title for free without having to care about it.
If so, use Safe Layout Guide
With the arrival of the iPhone X, apple introduced the concept of "Safe Area". For every iPhone except the iPhone X, it returns the top-most view bounds, but for the iPhone X it returns a rectangle that stops at the rounded corners.
In order to fix your issue, you should constraint your view's top to the top of the safe area, instead of the top layout guide.
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'm fairly new to Xcode and I am trying to create a simple app that is universal to support all iPhone screen sizes.
I'm testing this on an iPhone 5 screen and iPhone 6 screen.
I have the following constraints for the background UIImageView object, which expands to support both screen sizes perfectly.
For the View object colored in gray, I set the following constraints:
However, when I tested it on my iPhone 5 and iPhone 6, the View object remains the same size. It doesn't resize proportionate to both phone screen sizes because you can see how much space the View object takes as shown:
Is there any way to fix this?
Thanks!
For Gray view, besides CEnterX & CenterY, you need to define height constraints and Leading space and Trailing zero with 0 constant.
I have an app with a container view which has a UITableView embeded in it via an embed segue.
It looks and works perefectly on the 4" iphone but when I run it on the 3.5" simulator or phone it cuts of the bottom 40px or so of the list view.
I'm using autolayout.
The container view is set to autoresize children ( which it does. If I make the container view smaller it still cuts of the bottom 40px )
I've got the top and bottom bars of the table view turned off.
Any help you could give would be much appreciated.
Thanks
I have an iPhone application that runs perfectly on the iPhone 4s but when run on an iPhone 5 some parts of the screen doesn't autoresize. The thing that isn't resizing is the UIToolbar. My application always runs in Landscape mode, so the toolbar is at the bottom of the screen and these are the dimensions of the toolbar:
X: 0 Y: 256
Width: 480 Height: 44
I've tried adjusting the auto-resizing tool to almost every combination and nothing works. I can get the toolbar to spread across the screen, but the 3 buttons stay the same size. Each button is of width = 148. Is there an easier way to have the entire application just automatically resize correctly? For some reason my iPhone app worked great on the iPad when you used the "x2" resize view. Thoughts?
so the OP uses stock items and they don't resize then!
I would add flexible spacer items in between each button -- they resize
To solve my problem I just used IBOutlets that connected to each barbutton and if the screen size was for the iPhone 5, the width would adjust accordingly for each screen, if regular screen (iPhone 4s and below); then stay the same. Not a very efficient way but it worked for me.
Take a look at the images and select the autosizing red lines, if you select the bottom line it will keep on the bottom always, and if you select top and bottom it will stay at the same place. So verify your UIToolBar autosizing properties.
EDIT
EDIT2
Check out this answer How to detect iPhone 5 if you can't autosize, one quick solution that occurs mi if to change the frame in the code. Check if the device is a iPhone 5 or 4S to give a specific frame so you can adjut the width.