Storyboard UIViewControllers are too big for iPhone screen sizes - ios

Whenever I create a new project and select the single view application, the UIViewControllers are too big for any iphone emulator. How can the view controllers be resized to properly fit onto the screen? and how do I begin to make the interface be consistent across multiple devices with different resolutions?

Go to Attributes Inspector -> Select a View Controller -> In the simulated metrics ,change the size.
You can choose the size you need.

You talking about Size Classes technology, when you create universal layout for all kind of devices. You can switch between exact models of devices to adjust UIViewController size that you see.
However, if you wish to change the size manually, switch to Size Inspector and set Simulated Size to Freeform and enter values manually

You need to use the auto-layout and constraints to make the objects on the View Controller sit correctly

Related

Different designs for different devices ios

I have been creating an application for iPhone and iPad. I am using Auto Layout (wAny and hAny). Now I want a separate design for iPhone 4s alone. How can I use separate designs for this device. I already completed most of the designs with this wAny and hAny. How can I change this.
Edit:
I want to change only few view controller not all the designs.
I suggest not to go with different storyboards. You can add 2 views inside that viewcontroller's(for which the design is different) view and toggle it programmatically depending on the device. Regarding autolayout, set wAny and hAny and add constraints accordingly.
VC.view
-iPhone 4 View
-Other device's view
This can be done in storyboard only.
So programmatically when loading the vc, check the device and show the specific view hiding the other view. In this case in future, even if the design is normalized, you can easily use the same view with change in one line of code.
This is necessary if the design is totally different. Or if it's just few sub views which are different, I think you should write some code to hide and unhide the subviews acc to the device.
I am a novice in iOS, please correct me if I am wrong anywhere.
Better to go with design it as separate controls if you have design changes and load it conditionally for 3.5 inch screens . If its a simple changes (easily managed through codes) then go with codes itself.

Default size classes seem to only work for iPad (XCode 6)

I am trying to wrap my head around the new size classes in iOS8 and XCode6. I am attempting to create a nib, without a storyboard, and do something really simple--center a UIView on the screen.
Starting with a nib in the default size: w:Regular h:Regular, I place a 200x200 UIView onto the parent view and center it, then add contraints to pin it. In my preview pane, the UIView only shows up on the iPad view.
I need for this view to show up on iPads in lanscape and iPhones in portrait. I suppose some day i will understand why Apple thinks this is so much easier, but at the moment I'm bewildered.
When I switch my design view to any of the iPhone supported modes, the UIView disappears.
Even when I unpin the UIView and move it around in the design view, it never shows up in the iPhone view. In other words, I've tried everything to get this view to appear on an iPhone and nothing works.
Here is my UIView and settings:
Obviously there is something I'm missing, but I'm getting really frustrated trying to figure it out. Can anyone offer a clue? Thanks!
It's because you defined your view only for the size classes Regular & Regular. For them to show up on the iPhone you will have to configure the view also for the appropriate size classes, which in case of the iPhone is Regular & Compact where (<height> & <width>).
UPDATE:
The views generally only show up in the size classes for which they are configured. You currently have Regular & Regular selected, this can be seen from your screenshot. This means you defined it only for the devices with size classes Regular & Regular, which is the iPad in both orientations.
You need to add the views also in the size class that you are targeting, which are the size classes of the iPhone.

interface builder : make the view the same size as the iphone, to know exactly what constraints to add?

is there a way to have the view from interface builder in Xcode, be the same size as the iphone we use to test the app? The size of the viewcontroller seems to be 600*600. So when I move a UILabel somewhere to the left for example, it will be placed as if it was on the right on my iphone. Which is not easy to set the right constraints.
Do you have some tips to manipulate the items and place them easily? For now, I just align the item with the center point, and move it little by little.
The reason this happens is because of Apple's emphasis of size classes. It looks like a rectangle because whenever you are adding constraints and views, they'll be applied to every size class (i.e. horizontal/compact, vertical/compact, etc).
In english, it means it's applying those changes to run as such on any device.
To create constraints and views for just one size, you'll want to edit the size class you are working with. At the bottom of Xcode where it says "wAny hAny", click that and you can set what device you want to work with:
The whole idea of this is adaptive design, and I've got a post explaining it in more detail here.
The thing is that there is no one correct size for the iphone screen because there are so many different screen sizes. You can set the view size to anything you want in interface builder by clicking on the view and going to simulated metrics -> size but what you really want is autolayout so that your views fit properly on every device.

Xcode 6 Storyboard the wrong size?

Built a new project from scratch in Swift in Xcode 6 (Beta 1) and have seen some strange behaviour with Storyboards and the output that I am viewing.
I have built a simple interface (as shown below) - with properties of View Controller included.
When I run this in the simulator I would expect 'Hello, World' to be central in the user interface - however it seems that this 'Square' is simply being fit into the iPhone screen and thus the wrong view is being shown (see below).
My question is: has anyone else seen this behaviour and how did they fix it?
Thanks!
Do the following steps to resolve the issue
In Storyboard, select any view, then go to the File inspector. Uncheck the "Use Size Classes", you will ask to keep size class data for: iPhone/iPad. And then Click the "Disable Size Classes" button.
Doing this will make the storyboard's view size with selected device.
While Asif Bilal's answer is a simpler solution that doesn't involve Size Classes (which were introduced in iOS 8.) it is strongly recommended you to get used to size classes as they are the future, and you will eventually jump in anyway at some point."
You probably haven't added the layout constraints.
Select your label, tap the layout constraints button on the bottom:
On that menu add width and height (it should NOT be the same as mine) by checking their checkbox and click add constraints. Then Control-drag your label to your main view, and then when you de-click, you should have the options to center horizontally and vertically in container. Add both, and you should be set up.
If you are using Xcode 6 and designing for iOS 8, none of these solutions are correct. To get your iPhone-only views to be sized correctly, don't turn off size classes, don't turn off inferred metrics, and don't set constraints (yet). Instead, use the size class control, which is an easy to miss text button at the bottom of Interface Builder that initially reads "wAny hAny".
Click the button, and choose Compact Width, Regular Height. This resize your views and cover all iPhone portrait orientations.
Apple's docs here: https://developer.apple.com/library/ios/recipes/xcode_help-IB_adaptive_sizes/chapters/SelectingASizeClass.html or search on "Selecting a Size Class in Interface Builder"
In Storyboard, select your ViewController and go to Atribute Inspector. At the very top, under Simulated Metrics you have Size and Orientation properties which are set to Inferred. Change them to desired values.
In order for an application to display properly on another screen size, you also have to setup constraints, as described by Can Poyrazoğlu in the first post.
I had this issue in xcode 6 and there is a way to resolve the resize conflicts. If you select your view, at the bottom you will see an icon that looks like |-Δ-|. If you click on it, you're project will resize for different devices.
Go to Attributes Inspector(right top corner) In the Simulated Metrics, which has Size, Orientation, Status Bar, Top Bar, Bottom Bar properties. For SIZE, change Inferred --> Freeform.
On your storyboard page, go to File Inspector and uncheck 'Use Size Classes'. This should shrink your view controller to regular IPhone size you were familiar with. Note that using 'size classes' will let you design your project across many devices. Once you uncheck this the Xcode will give you a warning dialogue as follows. This should be self-explainatory.
"Disabling size classes will limit this document to storing data for a single device family. The data for the size class best representing the targeted device will be retained, and all other data will be removed. In addition, segues will be converted to their non-adaptive equivalents."
For anyone using XCode 7, it's very easy to design for a specific device size (instead of the default square-ish canvas).
In Interface Builder, select your ViewController or Scene from the left menu. Then under Show the Attributes Inspector, go to the Simulated Metrics, and pick the desired Size from the dropdown menu.
You shall probably use the "Resolve Auto Layout Issues" (bottom right - triangle icon in the storyboard view) to add/reset to suggested constraints (Xcode 6.0.1).

How to test behavior of Auto Layout constraints in xib without launching app?

I'd would like to see how the controls on my xib behave without actually launching the app.
In the Xcode documentation it says "[t]o test the behavior of Auto Layout constraints when you are editing a nib file, hold down the Command key and resize the window."
Does this only apply to OS X or is there a way to do it with an iOS app as well?
In xcode 5 you can preview how your view will look in different device screen and OS's. Open the assistant editor (Command+alt+enter) set it to preview and select the viewController you want to test. In the preview tab you can change screen size and iOS version.
What I have found to work is to switch your view controller under Properties -> Simulated Metrics -> Size to Freeform.
Your view should now be resizable with the mouse and the constraints will be in effect during resizing.
If you are designing full screen view, you cannot scale it but you may apply retina 3.5-inch form factor to view it in different height.
If you are putting views in container like UIScrollView, you may rescale the container to see if subviews moving or resizing as designed.
It is powerful when you are designing stand-alone xib for cell or custom views.

Resources