ios UI is not scalable for my storyboard - ios

I'm new to ios.
I have created a storyboard. I gave it's view size and location.
I intended it be scalable, so I used ration size and relative spacing.
However when I run the ios simulator I see the storyboard very different on iphone 6S and iphone 5 for example.
Here is my mock:
Here is my source-code
iphone 4s simulator:
iphone 5s simulator:
what can i do to make it scale right?

You need to use Auto Layout. While in your storyboard, click your ViewController and then go to the attributes inspector (in the pane on the right side of Xcode, the "attributes inspector" is the tab that looks like a down arrow), and for "size" make sure "inferred" is selected. If it is not selected, then click the drop down menu and select it. Then when you are placing objects on the view controller scene, you must add the appropriate constraints at times to ensure that everything gets scaled properly on different screen sizes. Read here https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/WorkingwithConstraintsinInterfaceBuidler.html

Related

Simulated Metrics size for "iPhone 5.5-inch" doesn't show the interface correctly in iPhone 6 plus device

I'm using xcode 6.1.1 version and iPhone 6 plus as testing device. I simply add a button at the right side of my xcode user interface, selecting Simulated Metrics size for iPhone 5.5-inch like this :
But when I run this on device the button goes far away from the right edge. Like this (Snap shoot from my device):
But when I select Simulated Metrics size for iPhone 4.7-inch like this :
It shows accurately in my device. Like this (Snap shoot from my device):
I tried with selecting and un selecting Auto Layout & Size Classes but do not get any clue. My device is 5.5 inch iPhone 6 plus. I even recheck it from my iPhone's packet and by IMEI Number. My question is why it is acting like iPhone 6 interface?? Is it for any reason of retina display or non retina display??
Thanks a lot in advanced.
My button's Constraints:
Select the button/ view you want. Then simply use the shortcut ⌥⇧⌘=. This will Reset to Suggested Constraints.
For this to work successfully, try moving your button to the suggested areas, i.e. move the button/ view to the top right corner like you have till the dotted blue lines appear.
Once done it should show what you expect on the interface builder but to be sure test on the simulator and/ or Device.
You need to add the proper constraints. Using simulated metrics is only for setting things up in IB, it has no effect on what the view looks like at run time. You should leave that setting at inferred.
If you don't add constraints yourself, the system adds them for you, and it adds top, left, height, and width constraints; that is not what you want. You need to add constraints to the top and right side. If you do that, the button will appear with that spacing to the right side, no matter what size screen you're using.
I think you should use constraints to solve the problem but i don't know the exact cause of this
Ctrl + drag from the item to the border in the storyboard to add constraints

Why are all my view controllers square shaped?

I'm trying to get it to be an iphone project, but when I drag any view controller into the storyboard, it's just a weird almost-square, neither ipad nor iphone. What am I doing wrong here? Newest version of XCode.
This is a new feature called "size classes". You can use it to create a universal storyboard for iPhone and iPad at once.
But I don`t really like it so here is how to turn off: In storyboard, open utility inspector (right), then go to file inspector (left) and now disable "Use Size Classes". Then you will get the standard storyboard.
You're not doing anything wrong. The default is to design with UI constraints so that the actual output size doesn't matter.
What you can do is set the size you want to preview your controller at in the options in the right hand pane. E.g.

iPhone app's storyboard does not display correctly on iPad

I've spent a lot of time attempt to research this issue and haven't gotten any results unfortunately.
[edit: being more explicit with my question]
My question is: why are the objects on my view controller not appearing when I run the iPad simulator? The background color of the view controller is displayed. The navigation tab bar appears as well. But neither of the two objects on my view controller appear (which have constraints on them).
[/edit]
If I look at the info.plist I see that I have "Main Storyboard file base name" with a value of Main (which makes sense, as my one and only storyboard is main.storyboard).
When I run the app within the iPhone simulator, all is well. When I changed the simulator to iPad, this is what happens:
Launch Screen appears
View Controller appears with the background color I have chosen in my storyboard scene.
When in debug, I see that it's going through the code to load up my views as it does when running in the iPhone simulator.
The Tab Bar controller's tab bar appears at the bottom of the view controller as expected.
Is this somehow related to the width and height I have selected? I have it set to: wCompact hAny. When I change it to wAny hRegular, the items I had placed in the scene (a UIView and a UITextField) "disappear."
Some background:
I originally created the app as Universal. But what I want, at least for now because I'm still learning, is just an iPhone app that will also run on an iPad (with that 2x option). I changed the Targeted Device Family to iPhone under both the Target and then later under Project.
I know one option is to just make an iPad layout, but I'd really like to know what I'm doing wrong here.
[edit: one solution]
The resolution I took, although I feel it's not the one I wanted, was to change the size to one that iPad supports and then paste the two objects (UIView & UITextView) into the scene that was defined as wAny hRegular. Then I hooked up those 2 objects to their outlets in the View Controller and I now have my app appearing in the iPad simulator.

Support of iPhone 4-inch screen by storyboard

I created a new project in XCode 5. And I run it on iPhone 5 (which has 4" screen) and a view doesn't cover all screen, but rather squeezed in 3.5" box (there are two black bars around my view)
I went to Main_iPhone.storyboard and checked that:
Use Autolayout is turned on on View Contoller
Use Autolayout is turned on on View
I tried Simulated Metrics, Size: Retina 4-inch Full Screen, Freeform and Inferred.
I tried to use button at the button to switch to Retina 4-inch form factor and 3.5-inch form factor.
Nothing makes a difference and it still shown as 3.5" (black bars around my view).
How can I make sure that iPhone storyboard occupies whole screen on iPhone 4-inch phone?
Update 1
None of solutions in this question: Xcode Storyboard displaying the new iPhone 5 screen size? solved my problem. BTW. That question was for pre XCode 5.
To enable your apps to work with iPhone 5, I suggest you to do two things.
First you need to add a retina version of the launcher image. It should be named Default-568h#2x.png.
And second use Auto Layout and make sure you have your autoresizing mask set up correctly for all your views.
I had the same problem, could not resolve it by any of the above methods. So what I did is copied the Content.json files from old project (where 4-inch was working) into the Images.xcassets Applcon.appiconset and LaunchImage.launchimage directories respectively. Then selected in the project setting in General under App Icon selected Source as AppIcon and in Launch Images in Source selected LaunchImage. It worked. Maybe useful to someone.

Simulator/device UI differs from storyboard

I am using Xcode 4.5.1 to create a very simple, single view iPhone app. I've laid out the view as you can see in the IB image. (UIViewController, UIView, UIButton, UITextView).
When I run the app in the simulator (or my phone) it looks like the second screen shot.
I don't understand why the simulator UI doesn't look like the one I created in IB.
What am I missing?
Thanks!
If you look you are using the iPhone 5 size layout in your storyboard file. To change the dimensions between iPhone 5 layout and the standard iPhone size
Click on the icon in the lower right hand corner of the storyboard:
Alternatively, if you want to see the layout in a iPhone 5 simulator. In the iOS simulator go to Hardware > Device > iPhone (Retina 4-inch). This is the iPhone 5 layout. However, if you do not have a retina displayed computer. The iPhone will look like a really big iPad.
It looks like you have an iPhone 5 sized layout in Xcode and a iphone 4 in simulator. Check the constraints on the dark grey vs bottom views and make sure that they'll resize how you want.
Hey so here is another method.
My Problem:
1.My Storyboard was showing a fat rectangle that didnt look anything like a iPhone. Then when I'd run the simulator all the element were cut off and not in the right position.
2.Simulator took up the whole screen.
Resolution:
1. Make sure you Storyboard is open and displayed, click on the frame so that it has a blue highlighted border. Then on the Utilities manager (on the right) click on "Show the Attributes menu". The very first item should be Simulated Metrics. Choose the size that best fits your screen/needs.
2.Follow Adjusting the XCode iPhone simulator scale and size I scaled it down to 33%
Best,
Nate

Resources