I am trying to run a simple sample using a nib file and it looks like this
However when I run it in my simulator it looks like this
My question is why is the alignment of the simulator not correct ?
The elements should be close to the middle and the screen height should be longer. Any suggestions on how I could fix this ? I am using Xcode 6.2
Here are the things I tried so far :
1 ) I made sure that the alignment in my nib file is set to Auto Layout.
These are the details of my project. I am testing on an iphone 6 as my simulator.
Any suggestions on how I can fix this ?
You need to set Constrain in AutoLayout if u don't want to use auto-layout then u can unCheck it .. you can refer this tutorial http://www.raywenderlich.com/50317/beginning-auto-layout-tutorial-in-ios-7-part-1
You probably need to configure size classes for the class device that you use.
If your app is only for iphone, you can also disable size and keep size classes for iphone only.
Hint Use preview from: Assistant editor -> Automatic > Preview, you will be able to see a preview of the view with all device screen sizes
Related
I would like to compact my iOS app also in iPhone X. This iOS app developed using autoresizing and deployment target is iOS8.
I had chosen my viewcontroller in storyboard.Then I tried to check Use Safe Area Layout Guide but it automatically appear check mark on Autolayout.Please go through the image.I want to compact iPhone X design of my app without autolayout.How to solve this issue?
You can't use Safe Area Layout without Auto Layout
Look at this Apple Document:
safeAreaLayoutGuide is member/instance of UILayoutGuide class.
And UILayoutGuide: is a rectangular area that can interact with Auto Layout.
So, you must enable auto layout if you want to use Safe Area Insets.
I think, there is no way.
Here is more detail about Safe Area of Xcode 9
Well, I have faced same situation where my old app which was made with Auto Resize thing and need to update with make it compatible for iPhone X, so what I had done so far is to adding splash screen for iPhone X, the following image will give you an idea to how to do this.
After doing that my app now compatible with iPhone X and i have to have add some new condition where design got disrupted. You can try this. hopefully it may help you.
Thanks
I have a simple single screen app with two buttons that looks great on the story board on xcode. As soon as I run the app on my iphone 6s, it resizes the screen and the buttons at the bottom disappear. It looks like the resolution has changed and the app is not meant for an iphone 6s screen.
I have already tried the following without any success:
1) Enabled "Use Auto Layout" for my View controller in the File Inspector menu(under utilities)
2) Set the deployment target to "10.3", Devices to "iPhone" and checked "portrait, landscape left and landscape right" for Device orientation under the General Settings.
Is there any other setting that I might have missed to check that is causing this scaling? I am using xcode 8.3
Edit: I recieved some great feedback in the comments section, and learnt about adding constraints. I am here adding screenshots of what my app looks like before and after adding constraints:
Here is my xcode storyboard (what I am looking to get on my iPhone 6s)
And here is a screenshot of what I have on my phone (prior to constraining)
I have tried constraining the view like so with no luck (same output on the phone):
Is there a specific set of constraints that will do the job here?
Your screenshots show that you have not set your constraints. The last screenshot shows that you have set some constraints on the root view. Like mentioned by Martin you need to have constraints for each object.
To place the button correctly at the bottom of the view, you need to draw from your button to your view (holding the ctrl-key) and then select the bottom, leading and trailing constraints.
I suggest to make a beginner tutorial in Autolayout with InterfaceBuilder.
Thank you for your great responses. Turns out the solution was a little different than just experimenting with constraints. It took me about 3 hours to figure this out, and I wanted to share the simple solution here in case someone else goes through the same thing in the future.
The problem was in the General section of the settings. Your Launch Screen File must reflect the MainStoryboard like so:
My Launch Screen File option was previously set to nothing which caused the problem. As soon as I changed it to the MainStoryboard, things look just fine.
Hope this helps someone!
I am having an issue with running my project on the device. Here are two pictures. The first one shows what the project looks like when I run it on the simulator. The second one is the same project run on the device:
As you can see in the first screenshot, I am using Auto Layout and Size classes. On the attributes Inspector I have the size set to iPhone 4.7-inch, but if I set to to "inferred" the same thing happens. I have done a fair bit of research on the web to see if I can find the solution but to no avail. I am fairly new so it could be something simple. Any help appreciated.
Update: I have set the size to inferred and turned off size classes and auto layout and I had resize all the buttons from 100 pixels to 80 pixels and now it looks fine on the device but I get the opposite problem on the simulator which was fine then. Is this an issue to do with iPhone 6 plus?
See next screenshot. On the left the storyboard and on the right the simulator.
Have you set attribute for it..? Because you are using size class.
Check it. If not set then set it for all objects.
It is just 2days to start iOS programming.
So I'm very beginner in this area.
<--This image is in iOS simulator. As you see right part is cropped.
<--This image is original UI.
I don't know why some parts have gone.
I am using MacBook Pro 2011 with Yosemite OS and brand-new XCode.
I tried cmd+1, cmd+2, cmd+3.
Please help me.
Thank you in advance.
Go to file inspector and uncheck the "use size classes" option, this is due to newly introduced size class feature to support all devices in ios 8
The new user interface works with all sizes of devices at once. The default size is 600x600 as you are seeing. When you simulate, is uses autolayout and constraints to arrange objects for the desired screen, aka an iPhone.
If you want to place the label in the center of the screen, Ctrl+drag from the label to the background, release mouse and buttons and the constraints options will appear. Click Center Horizontally in Container and Center Vertically in Container.
Run again. It will be centered.
Best regards
Select your view controller and find size inspector, Change fixed to freeform and give whatever size you want
I had a closely related question, and Mehul Thakkar's answer helped me to get where I needed to be, but I'm adding a new answer to flesh out both the question and answer a bit.
I was working on an iPhone app for iOS 8 that was shrinking the interface on larger screens to the size of the iPhone 4s. I don't use storyboards or Interface Builder nib/xib files at all, and do everything programmatically; for iOS 7 and earlier, I didn't bother making an explicit launch screen as my UI was simple enough that it loaded very quickly and a launch screen wasn't necessary.
Anyway, after finding this page and poking around a bit, it appears that creating a launch screen storyboard or nib/xib is now necessary on iOS 8, if you want your application to run at the correct size? (At least, I couldn't find any other way to coerce Xcode to do it in the project settings or whatnot.)
To do this, I created a new launch screen .xib file, unchecked "Use Size Classes" in the "Interface Builder Document" section of the File Inspector of that .xib file, and set the "Launch Screen File" under the General tab of my target settings to use that .xib. After that, the app ran at full screen size again.
This works for me and I guess I don't mind putting in a few minutes to turn the .xib file into a proper splash screen, but I'd be interested in hearing if there are other/better ways of making things work in iOS 8 and beyond, for those of us who hate our lovely code being tainted by the presence of those nasty storyboards/nibs/xibs...
So I am working on an iOS app that uses the UIWebView to serve HTML content. Why UIWebView and not WKWebView? well I want this app to work on iOS7 and above. I have just updated my Xcode to Xcode 6.1 and I cannot get my webView to scale to fit the available screen space when changing from the 4 inch screen size to 4.7 and above.
What I am after is to have my app look consistent on all iPhone screen sizes of 4 inch and above as all my HTML5 code that is displayed on the web view is.
In my Attributes inspector I have set the size to iPhone 4-inch and you can see what the app looks like in simulators for iPhones of size 4-inch and 4.7-inch respectively in the link below,
http://imgur.com/gallery/tz7LG/new
How do I get this to scale up appropriately on iPhone screens of different sizes?
fyi, I have set the Scale page to Fit to true for my webView. I am building this app using Swift.
To solve such issue,
1) Uncheck "Use Auto layout" and also disable size classes.
2) Open the size inspector to use Autoresizing as directed in the image below on the desired element (in your case its UIWebView).
Try selecting the bounds as per your requirements.
This will surely solve your problem.
Do check that you haven't coded the dimensions in the .m file.
The answer by Piyush Mathur is simple and seems usable in the given case.
But if the requirements are complex then you need to "Use Auto Layout".
Also make sure that you have set all the needed constraints of the Web-View.
The Introduction to Auto-Layout gives an idea to set constraints to a component which will also give an idea to stretch component (Web-view in your case) based on the device screen size.
You could use Xcode's auto layout tool, which will automatically resize the UIWebView according to the device.
I think the best practice is to untick "constraint to margin" when you add the constraints.
Here are three steps: 1. clear all constraints; 2. add the constraints back in and untick "constrain to margin"; 3. set all four constraints to 0.
Or if you are familiar with the Xcode, this can be done in one step.
What helped me is a creation of 4 constraints: