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

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.

Related

How do I install and uninstall a UIButton based on size class?

I need a button to be installed in portrait orientation while another button is uninstalled in portrait orientation (any width, any height), while the reverse should occur in landscape orientation (any width, compact height). One of these buttons is part of a UIStackView and the other is part of a UIView.
When in portrait the button in the UIStackView should be installed, but the button inside the UIView should be uninstalled, with the reverse occurring as I mentioned earlier in landscape. Currently I'm checking the userInterfaceIdiom in my view controller for the storyboard, but would like to rely entirely on Interface Builder if possible.
When removing my code (that actually makes it behave correctly), and simply relying on Interface Builder for installing/uninstalling the buttons based on size class, the button installed for landscape orientation always lays out correctly, but when rotating back to portrait, the other button that should now be installed is completely misplaced, out of it's original UIStackView, and that UIStackView that it should stay in, but hasn't, is now expanded to fill in the missing space where that button should have been. When this is happening, there are no warnings or errors from UIKit in the log, and my storyboard shows no conflicts. I'm thoroughly stumped!
At first glance this seems like an easy solution. Simply check/uncheck the install box for size classes of a UI element. Although, even after reading Apple docs and tutorials this is proving to be more difficult and obscure than I expected.
To clarify, I do not have constraints set for the button installed for portrait orientation since it is inside a UIStackView. On the other hand, I do have a few constraints set for the landscape orientation button. Although, the button in the UIStackView is the only one giving me trouble.
The view debugger is not working either in Xcode 7, and I'm receiving the error: warning: could not load any Objective-C class information from the dyld shared cache. This will significantly reduce the quality of type information available. when attempting to use it.
I believe this may be a bug and related to this post: UIStackView properties according to size classes
Your help is greatly appreciated! Thanks.
If you want a component to appear just in a specific size class this is what you do:
Add the constraints to you component using the size class you want it to appear in (wCompact hRegular for all iPhone in portrait and wAny hCompact for all iPhones in landscape). Next make sure that only that size class is ticked in the Attribute Inspector.
Leaving Installed ticked will make the component appear in any size class. You can change the size class of a view controller in a storyboard file by clicking on the option in the center bottom of the screen (see the blue bar at the bottom of the screen, where it says wAny hCompact in the image above).
I hope this helps!
UPDATE
Make sure that the constraints of the components are also set for the correct size class.
From the Document Outline select the constraints of the component and check the size class of the constraint in the Size Inspector. Usually, when you add constraints to a component with a specific Size Class selected in the story board, the constraints will automatically be added for that size class.

iOS: Size classes not changing for different sizes

I am trying to build a UI for my app using the storyboard in xcode.
I have recently changed the look and would like to have things slightly different for iPad as to iPhone. For example I want the cell height to be one height on ipad and another on iphone, with each different size adversely affecting where the label within the cell is positioned etc.
The annoying thing is I got this all working on a xib, but using the storyboard, I will build everyhting how I want it in compact width regular height for iphone, then go and build the UI for ipad in regular width regular height. Then go back to check things out for iphone and it has completely adopted what I have done in the regular regular size class.
This is infuriating, it effectively is pointless in having the size class, I may aswell use any any size class, but I don't want to. Images included below gives you a good visual representation.
so here I have made the UI for iphone
Then here is the ipad before and after I make changes
Then head back to regular regular (iphone) and you can see the size for the cell has changed
If I was to then change it back to how it was before, and the go to ipad I would be looking at the first ipad image i included above. So annoying, how can I get it to work with the different size classes?
You can't use sizeclasses to change the height of tableviewcell.None of the tableviewcell's properties can be modified by the sizeclasses.
When you choose a label or anything else that can be modified by the size classes ,you would see an "installed" checkbox at the bottom of the attributes inspector.You can install or uninstall a label in different size classes.
But when you choose a tableviewcell or a tableviewcell's subview,you would not see this checkbox.It don't make sense a tableviewcell appear in one size class but disappear in another.
You have to use tableView's delegate method to change the height of a tableView.

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.

UIViewController, Auto Layout and iPhone 6

We are updating our Auto Layout-using app to natively support iPhone 6 resolution. We added the iPhone 6 launch image, and most of the views scaled nicely.
However, we are experiencing a small annoyance: when loading new view controllers, the views have the iPhone 5 resolution on the UIViewController's viewDidLoad method. The view only gets the iPhone 6 resolution when you hit viewWillAppear.
Why is this? Is there anything we can configure or modify to make the views have the final resolution on viewDidLoad already?
I think the right place to get geometry data from your views is in the method:
- (void)viewDidLayoutSubviews;
This is called when auto layout finishes laying the views. Please beware this method can be called multiple times, i.e. after a rotation of the device.
EDIT
In interface builder, there is an option to set the size for the simulated metrics. I'm not sure if this has to do only with what interface builder displays, or also with the frame of the view at load time. Maybe you can change it and give it a try.

Default width of iOS 7 views

When I add a UIViewController to a storyboard in the latest xCode its view is defaults to 600x600 in size. This means centred items appear off to the right and the view extends off the bottom of the screen. Why is this?
Many thanks,
Ben
in Xcode 6 the interface builder works with AutoLayout. So you need to set constraints to your views to be in the right place. See here how thats works: Click me
But you also can disable the size class to work in the exact ViewController like this:
If you turn size classes off you see an window like this:
Just select the size class you want (iPhone for example) and you can work like you want it.
But I would recommend to work with AutoLayout due to the fact that there are a lot of different device types (iPhone 4(S), iPhone 5(S), iPad).

Resources