previewing autolayout with different sizes and language styles - ios

I've started learning the new Auto Layout stuff in XCode on iOS. Auto Layout is actually quite neat, but it appears to be a pain to test. I seem to remember on the Mac side there was a way you could Preview an interface and drag it to different sizes to test if controls lined up properly. Is there anything like this for iOS or some tool to facilitate testing your AutoLayout views? Additionally, something to switch to Right to Left would be useful too. I just want to test all my constraints and make sure they're perfect.

To view a preview of what Auto Layout will do under different conditions, do the following in Xcode 5:
Open up a storyboard.
Open the assistant editor (as many as you want).
In the assistant editor, tap the 4th button (the one that says Manual/Automatic/etc).
Choose "Preview".
You can now use the controls on the bottom right to customize:
the iOS version (6 or 7)
device rotation (portrait or landscape)
device screen size (3.5" or 4")
To simulate a right-to-left language, according to the WWDC 2012 Auto Layout by Example (Session 232) video:
Set the following arguments: (using a method such as this)
AppleTextDirection YES
NSForceRightToLeftWritingDirection YES
More arguments that can help with Auto Layout can be found here.

If you have localized strings, you can go to the Xcode Product menu then pick Scheme ---> Edit Scheme. In the top section on the right (Arguments Passed On Launch), click the + button and then type in: -NSDoubleLocalizedStrings YES and make sure the check box next to it is checked. This will double all your localized strings to simulate a language like German that tends to have long words.

Thanks to Apple we have the live preview in the new XCode 5.

One option for iOS i've found is to set Status Bar to None on root View of the XIB. This will remove the black status bar and show resize handles. This way you can drag the frame around and see how the controls behave. It still won't run code though. Also, I haven't found out how to enable Right-To-Left text yet.

Related

Swift layout not consistent

I'm making a simple learning app for myself to learn swift. I try to control my Raspberry Pi with my selfmade swift IOS app. Everything so good so far. The only problem is that my layout is totally different from my preview vs the live simulation... How can this happen?
Preview:
Simulation:
You need to add Auto Layout constraints to each of the labels and switches. The fastest way to accomplish this is to open your Main.storyboard file, select your view controller and navigate to:
Editor > Resolve Auto Layout Issues > Reset To Suggested Constraints
Make sure you select the option under All Views in View Controller.
Preview is just a rough approximation. You need to run it on the simulator or device for accurate results.

How to change labelCount on tablet? (when more space is available)

We are developing an iOS app using Swift.
We have a tableView where each TableCell is expandable.
It currently looks like this. (Ignore the abbreviation of the time label, this is not intended)
When executed on a tablet the labels from the expanded sub cell should be moved to the parent cell, depending on how much space is available.
It would not be a problem if we have to make a separate scene for tablets and phones.
It would be beautiful, if we could change the display of those scenes directly in the interface builder, depending on which device is selected on the bottom bar.
What is the best (cleanest) way to achieve that?
Thanks in advance.
What you need sounds like the "vary for traits" option in Xcode 8, it allows you to have different configurations of the same view depending on the device(actually based on Width and Height settings) but it narrow down to device as you use it, if you click the vary for traits button in Xcode you will see the various options for W and H and you can see in real time how the devices changes depending on your selection. Just be a little bit careful about one thing, when you introduce a new setting you use the vary for traits button but after that you access it from the right hand side picker as normal.
You will see in Xcode 8 that some attributes have a small + sign next to them, that is where you will find your different traits after you have introduced them, it takes some getting used to but is very powerful once you get your head around it. It is also the recommended way to make adaptive applications in iOS

iPhone App not showing up properly on iphone 6 simulator

My app works good on iphone 4s, 5 , 5s simulators. On iphone 6,it shows up weirdly. It does not occupy the entire screen
What could be the issues?
if you are using the Auto resizing just under stand the concept for example
assume that u have a book self , u need to layout the book in the book self so u need to do the following steps
initially arrange the book self (this is your main View).
arrange the all books in inside the book self where u need the location (this is your subview, buttons, labels, all UI Elements).
u keep to follow the above two steps in always. got it
need reference follow the apple tutorial
this tutorial may also help u
The black view is an added view? If the goal is just to set the background color, better to just set the color of the root view.
If you're not using autoLayout (and I don't reccomend it, it's more trouble than it's worth in most cases) one simple to handle different screeen sizes is programatically.
Everything in the view in Interface Builder needs to be an outlet.
in -viewDidLoad, set the center of each view. For example, to center the mobile number text: [self.enterYourMobileNumberLabel setCenter: CGMakePoint(self.view.center.x, self.enterYourMobileNumberLabel.center.y)]
You could also set the frame for more percise handling, etc., using margin constants. Frames are often more code and more cumbersome, but AutoLayout is a nightmare.
Resolved the issue. Thanks for your valuable responses users.It has got nothing to do with Autolayout or autoresizing.
Just go to images.xcassets, right clicking in the navigator area, add launchImage. Then select your project (or target), go to general-->App Icons and Launch images and set Launch Images Source as Launch Image and most importantly, set Launch Screen file blank.
The app would now work well in iphone 6 simulator too.

Changing simulated matrics screws up layouts in xcode

I built a nice fancy layout for iPhone and then decided I should try make it look a little better on the iPad. So, I changed some of the constraints (as I should have) and changed the Simulated Matrics to "iPad Full Screen". Things seemed OK until this point. However, when I changed back to iPhone, some controls were lost off screen, in the wrong place and some seem to have totally vanished. It's also not doing things like transforming a progress bar I use, but it used to.
One note: I started out with support for only iPhone. I went and changed that setting in my projects options and it said to me it was going to create a "Main-iPad"... I cant find this file anywhere.
1/ How do I recover the controls which have gone far outside the view
controller?
2/ Is there something I'm missing here? Each time I change the
simulated matrics, it screws up the other devices layout.
3/ Has the new "Main-iPad" storyboard file been hidden somewhere? Or
integrated into the "Main" file I currently have?
PS> 1st app and rather new to Xcode...
Thanks
To recover the controls you can go to the "document outline" in the project interface and find your object there. Then go to the size inspector an set the X and Y to 0, so the control will be reset to the top left corner.

Why does the iOS Simulator show only a blank view/window?

I'm new to iOS development. I used the Interface Builder to add text fields and buttons to my view. When I run the app, the iOS Simulator only shows an empty beige screen. What am I missing? The console doesn't show any error.
It is because you have not connected your view to your File's Owner.
To do this Right Click on the View, Control Click on the Oultlet of your View and drag it to the File Owner.
This shall solve your problem.
Cheers
I reckon it's because you have AutoLayout turned on in your storyboard, but haven't set any constraints.
Follow my instructions in the following article, to confirm if this is true.
AutoLayout problem
Basically, with XCode 6, if you have AutoLayout turned on, you must set constraints on every single control... otherwise your screens will look fine within XCode, but the controls in your screen could (and will) end up anywhere and in any size when the app is run.
It's like designing a beautiful webpage, then displaying it in an angry, drunk, disorientated browser.
XCode is really unintuitive, and unhelpful for beginners... but once you learn the rules of AutoLayout (along with its many quirks), it's reasonable useful.

Resources