I'm new to iOS 8, I tried to load a UIView from XIB file with auto layout and size classes option are enabled. I use Inferred size XIB with default size is 600 x 600. But on the simulator the size of view is not fit screen size, it still be 600 x 600 and doesn't fit the screen size like this, it's much bigger than the screen on width:
But when I use View Controller widget, it has Resize of NIB option, and it work fine to fit the screen size. Can anybody suggest what should I do to resize UIView to fit screen size? Thank you very much, guys!
Update:
Here is how I call it:
And constraint I use:
You should use autolayout and set constraint. It is better choice if you need to support multiple device.
Try to figure out with these 3 images first. Then I am discussing one by one.
http://imgur.com/mE2dNm8
http://imgur.com/PVW6yrk
http://imgur.com/LLZkMgx
Related
So I have the following layout in storyboards, everything works fine on the 3x screen sizes but I would like to try and tidy up the font sizes and the position of the button icon relative to the button text.
See below what I mean, basically what I want is for each screen size to look very similar to the 4.7 screen layout e.g. the spacing between the text and the icons (also how can I get the font to scale down slightly on the 4 inch screen as it looks too big but ok on the rest of the screens.
Any idea what constraints I need to put on the icons and text to get it to look the same on each screen size.
In auto layout use multiplayer to increase and shrink the element. Please see the example below:
Now run your app and check in all device type. Hope this will work for you.
If you are using autolayout, you can set aspect ratio constraints for width and height of the imageView to the cell content view, that way, if the cell grows image will grow too.
The following link might be useful http://candycode.io/how-to-set-up-different-auto-layout-constraints-for-different-screen-sizes/
I was looking at this youtube video https://www.youtube.com/watch?v=vzyd33Pv9kg regarding How Priority Constrains works.
I want to do the same but instead of label I am using custom buttons with images. As you can see in the video, the author hardcoded the size of the label to 100wx100h. However regardless of the what iphone you have, the labels always be the same size. I want to accomplish the same thing, but instead I want the size of buttons (or in his case labels) be larger on iphone 5, and even larger in iphone 6 and so on.
My question is how can I accomplish this?
Also is it possible design this with let say 100X100 in 3.5-inch iphone then change the size dynamically change in the code depends what iphone is used?
if iphone4s then use 100X100 size buttons
else if iphone 5 then use 110X110 size buttons and so on?
Yes you can. Just connect your relevant constraints(width and height constraints in your case) to your view controller like usual elements. Than you can change constant property of your NSLayoutConstraints (Probably in your viewDidLoad method).
self.buttonWidthConstraint.constant = 110.;
self.buttonHeightConstraint.constant = 110.;
You also may want to change size classes to provide different constrains for each orientation.
https://developer.apple.com/library/ios/recipes/xcode_help-IB_adaptive_sizes/chapters/AboutAdaptiveSizeDesign.html
I am new to IOS programming and would like to display a square image in a UITableViewCell, so size would be 320x320 or 375x375 for iphones 5 and 6 for instance.
Can this be done with a single xib file or two different XIB?
If it's 2 XIB, what is a good screen size test for registering the correct nib as a tableview cell?
You can use single XIB using AutoLayout and Adaptative Layout provided by the Size Classes : Apple Doc.
Size Classes allow you to deal with different sizes. [Regular] - [Compact]
You should found here what you are looking for.
You can do this in a single xib. Using autolayout, you have to add a constraint to specify that your cell's height should be the same as its width. This way, if the width changes your height is automatically updated.
I have UIViewController on storyboard.
On the image you can see top gray is simple UIView while bellow is UITableView.
And I set uiview to be 150 height.
I use autolayout.
Problem is that when I run app on iPhone 6 uiview height is about 40% of the UIViewController.
From some reason it's height is larger than 150.
Can somebody explain me how can I setup view so I have UIView always the same size?
I think the problem is with your view height....you can not give static height.... see the images and check out where you missing out....
and the o/p is in 4.7 , 5.5 , and 4 inch is
for all the height of view is looking same....that is of 150 height
Have you included an iPhone 6 launch image? My guess is that the iPhone is resizing up based on the resolution of the 4" screen. Include either a static launch image, or a dynamic, xib-based one, and I think that should fix your problem.
I am using Xcode 6.1 and in one of the views I have, contains many labels. However, these labels look different in each different devices. Although I have add constraints to all the labels, but still facing the same issue.
How can I get the same view layout across all devices?
How can I make the width and height for each label is flexible, depends on the screen size?
Do I need to design different xib for each device?
The following images showing the result am getting, with auto resize enabled, and constants been added.
on iPhone 6
on iPhone 5
on iPhone iOS 7.1
We have provided with a simple solution . Using Aspect ratio constraint we can get a relative look in all device screens.
I had the same issue and I found this >>
http://mathewsanders.com/designing-adaptive-layouts-for-iphone-6-plus/
So when designing for lowest to highest screen resolution we can't set a specific width and height for all controls as it may look weird. So using this constraint we can have a relative look for all screens.
If you don't want to use constraints or you want to keep the same width & height , you can add scrollview to hold all controls. For that you can set a resizing frame for scrollview with fixed content size .
To solve this...
1) Go to xib file and uncheck the Auto layout
2) Then set the autosizing manually in the following manner for each and every subview.
Use self.view.bounds.size.width to get the width of screen, then use relative value to initialize all labels.
One soultion is that you can Design a story board for each screen size like one for iphone 5, one for iphone 6 and one for iphone 6+ and in your AppDelegate method "didFinishLaunchingWithOptions" you can get the screen size and popup corresponding storyboard
in this wasy you can set different constraints according to different screen size