I've been trying to figure out how to code up a launch screen that is not in Xib form. Reason being, I cannot for the life of me figure out how to do a decent job with Auto layout and constraint building. Please do not suggest that I pursue that course of action.
I was thinking of implementing a custom UIViewController (with a Xib to hold just a reference to the view controller instance) that I could set with a black background and 5 UILabel subviews. That Xib will be used as the "Launch Screen File". I have the necessary methods to make sure the labels always resize properly given different device sizes.
However, is that even the right way to go about it? I'm really trying to refrain from just creating a Xib and using that, or drafting up an image in Photoshop or something like that.
Related
I'm going to get heat for posting this question that has probably been answered multiple times before, but I wanted to get a new understanding on how to incorporate Storyboards and auto layout into my app.
The whole thing is done, but I've used countless Xib files that don't even have a proper view layout to them. Everything related to image position and size is done through hard-coding CGRect(x,y,w,h) frames. I'm not using auto layout, and my Xib files are not populated with proper views (just temporary views to provide the IBOutlet connections).
What do I start with first? Auto layout or transfer everything to Storyboard? What documents/guides can I read to help me with this?
I'm using Xcode 7.1.2, and iOS 8.1.
All the Xibs needs to converted to Storyboards first, so that the entire app has all its Screen is reflected in the Storyboard.
Once this is done you should start implementing the Autolayout, by removing the hardcoding from the code and managing them via the StoryBoard scenes.
I am starting a new project which should be working on every iOS device size possible.
The project is rather simple. The main view will be a scroll view and it will hold a '+' button (where it says 'button' in the image) in the top right corner. (It does not really matter, I'm just trying to give the general idea of what I'm trying to understand and implement.)
A small example:
What is the right approach for this kind of problem?
Should I create a different storyboard for each device?
Should I start creating an adjustable scroll view that will hold the needed buttons with some constraints (if at all possible)?
I have read this tutorial:
auto layout
which explains the auto layout nicely, but does not mention the issue I'm trying to figure out.
Any thoughts?
Use AutoLayout and position your views relative to one another (so no x pixels spacing between views). Make only one storyboard for all devices, when a different view should be loaded on another device (like a completely different layout), select the appropriate size class and adapt the views and constraints.
Then it will be recalculated on every device.
The storyboard has a preview section where you can choose a device to simulate the view on.
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.
I am putting together a sample iPhone app for practice. It is a drill-down interface with doctors who have patients who have prescriptions and visits using Core Data and a story board.
Everything was going great until I started on the Edit/View doctor screen. Because this screen is triggered by a button in the UITableViewCell, it seemed that there was no way to create a segue on the story board to an edit/view screen because the buttons in the cells are dynamically created.
I decided to make a separate UIViewController custom class and I let Xcode generate the XIB for me to make sure I did not mess up anything. I presented the edit/view view controller by pushing onto the navigation controller. The problem is that the contents of the edit/view screen were nearly completely off the screen. With my first attempt, a navigation bar I put at the top appeared at the very bottom of the screen in the simulator with all of the rest of the text fields and labels not showing at all.
I then created another view controller with xib, specifying iPhone only and simply put a label with "Hello" in the center of the view. When I ran the simulator, "Hello" was centered vertically, but was all the way to the right of the screen with only "He" showing. I tried played with anything I could find to play with, but nothing fixes it. I am not trying to do anything unusual. I want to do everything in the usual accepted way.
Also, it seems like Interface Builder makes the views look like big square iPad screens even when I have specified iPhone. I did check the frame dimensions and it was wxh = 600x600.
Thank you for your help.
It occurred to me to search for 600x600 and it seems that this is the new UIView that Interface Builder provides by default. Because there are many screen sizes, Constraints are apparently mandatory now.
My edit/view form was completely fixed by viewing the XIB and going to:
Editor->Resolve Auto Layout Issues->Add Missing Constraints.
So i'm learning how to use scrollviews and i've got one working successfully.
When working with an xib file, it's easy to work with a scrollview as I can put a scrollview on the background/ workspace and set the size, how I want my labels and buttons to sit on top of it etc and then when i'm ready, move the whole thing onto my View.
The project i'm currently working on uses storyboards and so I don't have the ability to put the scrollview on the workspace and get my size and arrangement right.
Is there a workaround? What's the best way to do this?
Thanks
You just need to add your scroll view to the view of one of the storyboard view controller's views, and then you can do the same things with it that you could do in a xib file. Also, even if your project uses storyboards, there's no reason that you can't have a xib file as well.