IOS / Swift - How to adjust font size and margin size for each devices screen sizes with autolayout - swift

Coming from the Android world, I'm trying to create my first IOS app in swift.
Actually stuck to build interfaces that are adpative to all screen sizes from Iphone 5s to Ipad 12.9".
Autolayout works well except that I can't find how to easily adjust font size and margins for each screen sizes.
Maybe I've missed or miss-understood something in my research but my question is :
How can I have big margins/font sizes on big screens and smaller margins/font sizes on smaller screens ?
Is it possible to have like a constant for a margin for each device or range of screen size in one place so I can easily change it ?
Update :
I forgot to mention that I also tried variations on constraints and font size but theres just a few options between "regular" and "compact" and if you need to change a margin you have to change it on all your elements it's seems crazy..
In Android there's a dimension xml file by each screen size/resolution you want where you can have contants and assign them to each element you want.
I can't figure out the logic behind IOS here
Thanks in advance

Related

Autolayout - How to Change width spacing between iPhone 6 and Plus

Ok, I have been pulling my hair out for a few days now and thought I would ask the community how to deal with width sizes or the gaps between buttons in xcode 6.4 or 7 (tried them both).
Ideally I want 2 buttons near the bottom and they need to scale properly based upon iPhone portrait mode.
I have added the 1x, 2x, and 3x pngs of the button to the asset system and my auto layout is set for wCompact hRegular which from what I understand allows you to target all iPhone devices in portrait mode.
So after adding my buttons I had it do add missing constraints which added a few and seemed to work pretty good but the issue im running into is the gap spacing between the 4.7 inch and 5.5 inch and how to adjust each one of those separately in interface builder if possible.
See the image below where I outline the gab space and its quite huge for the 5.5 inch.
Also it would be awesome if I could use bigger images for the bigger phone but thats another subject I guess.
Since I cant post images here here is the link to the story board
Take a look at this repository..
https://github.com/mahesh-agrawal/Test-Autolayout-Buttons-Spacing
i have added required constraints to make the gap between the buttons dynamic for all devices. also i have made the width and height dynamic by giving proportional width height.
I have taken two views and given them horizontal spacing 0 and equal width and leading and trailing required for each. and then i have taken two buttons in each and managing width of button with proportional to the views so they will increase accordingly and also the gap will increase accordingly. Test in all devices.

Choosing the appropriate wrapper sizes in responsive design

With all types of screen resolutions and devices - desktop or mobile, it's kind of hard to pick the right widths for your website. In my case, the website is to present a photographer's work so I've opted for these widths:
1340px
1180px
1000px
480px
But say an iphone 4S (native res is 960 x 640) is positioned vertically, what wrapper would the device display? Would it resize the 1000px wrapper into 640px or would it pick the 480px?
You'll want to start by learning the basics of Responsive design. Check out : http://www.abookapart.com/products/responsive-web-design
Due to the ever changing nature of device sizes, you may want to avoid trying to target specific devices/resolutions. Start with a narrow screen and expand your window until the layout breaks. Add a breakpoint there. Continue expanding and adding breakpoints as your content dictates.

Font size varies for different iOS devices

Can any one tell me how to handle font size for different iOS resolution devices?
I am working on cocos2dx and using CCLabelTTF.
What happens is that same font size appears differently iPhone and iPad-HD.
Font size is perfect for iPhone and is pretty small for iPad-HD. I know its because of different resolutions so What is the solution.
One easy solution is to detect device and set size accordingly but it will take 5-6 checks which i dont consider a valid solution. Can any one else have a good solution ?

converting iPad app to iPhone app

I'm currently working on an iPad-specific application.
Since I don't use interface builder, every view element is using CGRectMake with specific numbers for its position and size.
so I was wondering,
if I use the same exact code on iPhone, do these numbers scale accordingly?
or should I re-insert the numbers for all the view elements?
If the latter case, is there any easy way to change it all?
CGRect coordinates are absolute, so your subviews will not automatically scale down to the iPhone. If you run your code on an iPhone, you will see only the upper-left corner of your iPad layout.
You can pretty easily write a helper method to take the original CGRect values and scale them down for the iPhone layout. However, if you're also drawing text you'll need to scale down the font sizes as well (which probably won't work, so you'll still need to deal with the text in a possible not-automated way).
I'm doing essentially the same thing right now, writing a single app that runs on both iPad and iPhone and scales itself in code to the available dimensions. I'm generally setting up the view layouts as a float proportion of the available screen size, and then converting those proportions to CGRect before rendering.
Kudos on not using Interface Builder by the way - IB may be the most ridiculous atrocity I've ever seen in the programming world (even worse than classic ASP, which is saying something).
You'll have to change your numbers for your iPhone app. The points that CGRectMake uses are pixels and don't scale, with the exception of HD devices like the iPhone 4.
Honestly, the iPad is such a different device that your UI probably needs to be heavily modified to take advantage of the extra screen space.

When I create an iphone window based app, how to tell interface builder create window for retina pixel size?

I hope to create an iphone window based app for retina screen?
But I found that the size of window in mainwindow.xib is fixed.
How to adjust it or there is any to tell interface builder create window for retina pixel size?
Welcome any comment
Thanks
interdev
There's no need to do anything in terms of the various components you layout in Interface Builder, as it's based around points, not pixels - and as all the iPhone screens sizes are the same in points no action is required.
In terms of any images you're loading, you will need to supply higher resolution (twice the pixel size) versions, but as long as these are named "[original name]#2x.[extension]" they'll simply work automatically.
For more information on the image naming, see the "Specifying High-Resolution Images in iOS" section of the Resource Programming Guide and if you want to delve a little deeper, there's a discussion on "Points Versus Pixels" within the Drawing and Printing Guide for iOS.
UPDATE - As of the iPhone 5, the iPhone screens are no longer all the same point size. :-)
The window will be automatically resized for you, you do need concern about the size of your image elements, since retina display uses a bigger size of resolution. You need name your images like this:
regular image name: myimage.png
retina image name: myimage#2x.png
When running in an iPhone4 your program will identify the token "#2x" and change the images for that kind of device.
Design your layout using the size of: 640x960 (double of the original: 320x480)
Good luck.