Resize Uibutton with Auto Layout & size class - ios

I have developing app for iPhone & iPad. so I choose Auto Layout & Size class its bit complex to understand. I have tried to add number pad with my app Please refer the screenshots.I added iPhone 6, iPhone 4s and iPad screenshot. I want exactly iPhone 6(screen1) output. but I cant get it in iphone 4s(screen2).
in iPad(screen3) atleast need to show those buttons at center of the screen. can any one help on this.
I try to set less or greater then size to buttons but its not working. please suggest me how to make same look on all screens.

In order to achieve the same results for different iPhones and iPads you must actually work with and implement the size classes you chose. Please refer to Apple's manual at: https://developer.apple.com/library/ios/recipes/xcode_help-IB_adaptive_sizes/chapters/AboutAdaptiveSizeDesign.html
Another great tutorial is at: http://adoptioncurve.net/archives/2014/08/working-with-size-classes-in-interface-builder/
As you mentioned in your question- size classes might be less intuitive. From my experience, reading Apple's manual will help you understand how to accomplish exactly what you need.
I hope this helps.

Related

How can i attain responisveness for ios apps

I am working on an application in ios swift.
This is how it looks in iphones.
and this is how it looks in ipads
I have used tableview to make this app. How can i fix it to look good on ipad too.
There are many ways to do it, one of those is you can use auto layouts and differentiate between iPad and iPhone using size classes.
Add a variation in size inspector if you are using storyboards. For iPhones its Compact width and Regular height and for iPads its Regular width and Regular heights.You can visit this link https://www.bignerdranch.com/blog/designing-for-size-classes-in-ios/ for more details.
If you are doing through code then you can differentiate between iPhone and iPadusing below code snippet
if UIDevice().userInterfaceIdiom == .phone {
//This is iPhone
//Here Provide your content size for iPhone
}
else {
//This is iPad
//Here Provide your content size for iPad
}
You want to use a stackview. Basically group your widgets horizontally or vertically inside stackviews. The stack views can be nested. You should not use any constraints except on your scrollview itself.
There was a wonderful WWDC video, I think from 2018, that of course I can't find right now. But AUTOLAYOUT and STACKVIEW are the keywords for which you want to search.
Here is one but it isn't the one I'm actually looking for. It should get you started though.
The "direct" iPhone app "translations" for iPad very rarely look perfect. You might want to think about redesigning your UI to use the available screen space better. The size classes and proper autolayout will definitely make your app look better but will never make the app look like it was tailored for the iPad.
You might want to think about redesigning your UI not to only re-size properly but also provide more usability on devices with larger screens. A couple of UI components that can help you do that are UICollectionView (https://developer.apple.com/documentation/uikit/uicollectionview, https://www.raywenderlich.com/9334-uicollectionview-tutorial-getting-started),
and UISplitViewController (https://developer.apple.com/documentation/uikit/uisplitviewcontroller, https://www.raywenderlich.com/265-uisplitviewcontroller-tutorial-getting-started).

Autolayout(xcode 6,swift)

In I phone 5s simulator its working fine! I have one label,one image view and one button.As you can click on the link and see the picture now so i tell you that I used my image view as a background and the label is in the middle and the button is in the lower middle so i want that to look same in all the devices. i don't know anything about constraints.I am using Xcode 6
https://drive.google.com/file/d/0B2z_d4wEKPEFLV9RNFVlR3A5SFppa0tJT2tiQkQwVVVVTDVz/view?usp=sharing
I suggest you to take a look at this youtube tutorial. I learned how to make the constrains by watching it. The tutorial teaches how to make the similar layout as you required.
Link: https://www.youtube.com/watch?v=RpMzEmF-xZM
Hope this is helpful~
Autolayout is the tool used to make UI look similar across all devices, you should try to learn it if you want to continue to develop IOS apps. The concepts are pretty basic and are used throughout other languages.
This tutorial is useful if you want to create the auto layout using storyboards.
This tutorial is useful if you are making the view programmatically. I tend to use code for auto layout but it is just a preference, storyboards is fairly simple so I would suggest that. If you are going to do it in code a is to forget setting the autoresizing mask into constraints to false. You have to set this property on all the views you want to use auto layout for.
view2.setTranslatesAutoresizingMaskIntoConstraints(false)
Background ImageView
Select Image ->Pin->Uncheck Constraints to margin-> select top,bottom,left,right.
Button
Select Button-> Pin->Uncheck Constraints to margin->select bottom,left,right,Height.
label
Select label->Align->Center horizontally and Center Vertically in Container.
Pin->Width,Height.
If it is working for iPhone 5 but not another layout then this is probably happening.
There are demensions in the centre of the lower tab bar of story boards
There are screen size settings in the story board and regular*regular is the only one that is universal to all orientations and sizes of the ios device. if you set constraints while viewing in regular by compact (landscape for 5.5 inch iPhone) then those constraints will only be apply to 5.5 inch iPhones in landscape and if you tried running on a smaller iPod it would be as if you never set the constraints. the constraints for the 5.5 inch iPhone would not apply to the small iPod
if constraints were made in compact by compact and you were viewing the story board in say regular by compact then you would get an error saying that things are misplace and will not appear in the same at runtime. view the storyboard in the same dimensions that you set the constraints and you should not have an issue.
There is an option to simulate the device you want to run on specifically in storyboard and it can be say only 5.5 inch iPhones or something, whatever device.
go to paul hegarty developing iOS apps with swift on iTunes you if you want to learn more. He is a good source.

Xcode 7 size class issue?

So I have an app and I want a very different layout based on size class. And I thought I'd accomplished this today because the storyboard preview showed every device and every size in every orientation doing exactly what it was supposed to do. When I ran this on my device and then the simulator however, the size class seemed not to change as the layout was pretty much the same thing as before. Here is screenshot showing my issue. Please note that the psycho spray painting was done by me not Xcode:
So I was hoping someone could help. In case you're wondering, I did the psycho spray painting to protect some confidential info which I thought was pretty obvious but there you go :)
Thanks for reading and thanks in advance for the help!
EDIT:
Here is a screenshot of all constraints for the two main size classes. The green and blue objects that are blanked out do correspond. So the blue thing up top is the blue thing in the constraints. The green is label and slider of the same part of the app's functionality which I don't want to reveal. For now all I'll say is that it's a music app as you can tell by looking at the photos below.
Okay I found the problem! I forgot to resolve some issues in my Compact width and compact height (aka 3.5,4,and 4.7 inch iPhones in landscape) which forced it to use the previous size class's layout.

Understanding IOS8 size classes

I have been playing around on Xcode with size classes to try and make sense of it. The problem I have is that many different sized phones all fit into the same size class (like all iPhones in portrait) so I can't home in on a 3.5 inch screen for example. This is frustrating as I would like to change the layout constraints between phones rather than just classes as obviously I need to make the gaps between things larger or the buttons slightly bigger to keep everything in proportion. I don't know if it is something I have missed but it seems the only way I can do this is by creating every single layout constraint I want to change as an outlet and then testing in code for each phone and updating it using a rough estimate and run the thing on the simulator.
In Summary, how can I adjust the constraints based on the size of a device, when they're all in the same class? Using a percentage/proportional constraint should give me the result I'm after.
Apple have designed it so that you don't have to think about specific devices. The idea is that you use auto layout so that each screen automatically adjusts to the available space. Size classes is an extension of that so when you get a lot of extra space you can do something slightly different.
If you want to customise your layout to specific devices, you can. Pretty much as you describe it. However, what happens next year when Apple release the iPad Pro and a 4.3" iPod touch (you read about it here first)? In general, there is no need to hard code spacing and sizes; your interface should scale to use the space available, and that's what auto layout and size classes give you.
It's certainly harder to think it terms of constraints rather than a list of known screen sizes, but it should be worth it.
Well, Size Class has many advantages. It depends on how people viewing it. In specific to your question there is a way to change for all iPhones in Portrait and all iPhones below 4.7 inch Size in portrait.Below is the image of that. I can understand supporting 3.5 inch screen with size class is difficult. Setting a proper constraint and using the below class will help you to achieve it.

Fit an iOS application developed for 4 inch screen to 3.5 inch screen

I am writing my first iOS app and just realized a serious problem. I was using storyboard for a 4 inch iphone screen and forgot to take 3.5 inch screens into consideration. :( It seems that this could be relatively fixed easily if I have done everything in code. But unfortunately, I have used storyboard for some parts of my app. It seems that the table views are fit perfectly but the views with some fixed subviews fail. Could anyone please give me some suggestions on how to fix this? Any help is appreciated. Thank you very much!
This is exactly what auto layout exists for. You can create a UI, using storyboards, that works perfectly for both screen sizes. You can toggle a setting in the storyboard to have it display the two different screen sizes, so you can easily see how your views will move and resize. There is also a preview mode for the storyboard that lets you see how it will look. It also lets you see how it will look on both iOS 6 and iOS 7, so that you can make sure that your UI looks good on both assuming you still support iOS 6.
If you had done this in code, it would probably have been a whole lot more complicated, especially since you have to run it each time to see what changes when you adjust your code. Graphical layout tools such as Interface Builder (what allows you to view and edit storyboards and XIB files) make supporting multiple screen sizes very easy. Plus, generally it's not too hard to make a screen designed for a 4" screen work with a 3.5" screen, in some cases you just have to make things fit a little closer together, or perhaps have the content in a scroll view.

Resources