Swift layout not consistent - ios

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.

Related

Simple IOS Layout

I have been trying to do this layout for a few days now and cannot do it. I have no code as I have been only using Storyboard.
In my Android version I simply used a weighted LinearLayout where my title was 20% my relative layout was 60% and my custom object was 20%.
I cannot replicate this in IOS. Everything I try fails. I have tried everything and have tried using StackViews, EqualHeight constraints with multipliers and everything does not work. Most of the time nothing even happens and it just looks the same. Can someone please help me? I am so frustrated I am considering abandoning XCode in total and coding my app in React Native.
It's not really clear what you're asking. But if you want to use storyboards, it's pretty easy with XCode. You can set your layout visually, then simply use the "auto-resolve" feature (little triangle inside of bars on bottom right above the console) to: 1) "clear constraints" and then 2) "reset to suggested constraints". This is a fast and crude method that should more than enough to get started.

Multiple xib for defining a page?

I'm implementing a lock-screen page in iOS.
But the design for iPhone 6 requires text on top is pretty large, which causes the bottom in the page is hidden in devices equipped with small resolution screen like iPhone 4.
Do I have to define multiple xib for each device in this situation?
Or make some views smaller programmatically?
Or make some margins smaller programmatically?
Are there any references for this? I'm new to auto-layout.
I would suggest you to use autolayouts. From my understanding your app can be implemented with stack views.
So start with this document,
http://www.appcoda.com/introduction-auto-layout/
and
http://code.tutsplus.com/tutorials/ios-from-scratch-with-swift-auto-layout-basics--cms-25520
Then checkout the apple documentation for further understanding
https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/
If the constraints are too confusing, try stack views
https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/AutoLayoutWithoutConstraints.html#//apple_ref/doc/uid/TP40010853-CH8-SW1
Creating multiple xibs is not a solution. Make use of autolayouts :)

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.

iOS 7 Transition - XCode 5 - Interface Builder - Three20

I've currently an App (with a lot of View Controllers, ...) what uses the "discontinued" Facebook three20 Library and any storyboard, xib file.
Now I need to update this App, the Deployment Target will be iOS 7 and I have to build it with XCode 5.
So my questions:
Is using the Storyboard a good Idea? Would you suggest me to recreate all View Controllers in the Interface Builder?
--
Another question: when adding a Label Programmatically using iOS 7 feature
self.edgesForExtendedLayout = UIRectEdgeAll;
how do I set the Frame for this Element? Need I determine if I am in Landscape, Portrait and Add the 20+44 for example manually to the y-Axis to start under the NavBar or are there better ways to solve this problem?
Storyboards are good, and you should absolutely use them in any future app you make. Whether or not you should rebuild a current app to use storyboards is a question of how big the app currently is, how much bigger it might get, how much longer you'll support it, etc.
If the app is already pretty massive and it won't necessarily grow much at all from here, it's probably not worth the effort to convert over to storyboards.
If the app is only a handful of view controllers, but you have big future plans for it, I'd take the time to convert it over to storyboards so that all the future development will go faster/easier.
I don't deny storyboards but I respect the custom view approach. It means I am creating my each & every component programmatically via code, be it a UILabel or a UITableView. Aligning code with ios7 specific requirements can also be handelled & controlled at granular level using custom View approach.
To your questions about setting frames for the element or detecting device orientation can very well be detected & adopted by writing code.
You can search more help as the information is available all around on programming aspects of iOS.

previewing autolayout with different sizes and language styles

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.

Resources