xcode auto resizing xib not proper on iphone 6s plus - ios

I am using auto resizing xib in my application.
I disabled size class and auto layout.
this is how i set xib.
And this is how its looking on iphone 6s plus
How can i fit xib to all device without using auto layout and size class?

actually you set the layout for every label in left corner, thats the reason its showing full left.
for your First label Size inspector is correct, if you need the modification do like
for your second Label do like
for your third and Final label Set like
Update

You can set label positions & width like see images:
Label 1:
Label 2:
Label 3:
Note: this will adjust the uilabels width & position according to the diff screen size not height.

Related

UIStackView subviews with size classes

Trying to achieve UIStackView with 2 labels for iPhone and 3 labels for iPad using size classes.
View hierarchy
Default size class
[UIStackView]
[UILabel 1] [UILabel2]
[UIStackView]
RxR size class
[UIStackView]
[UILabel 1] [UILabel2] [UILabel3]
[UIStackView]
It looks exactly as expected in Storyboard as you can see in the above screenshots but on simulator iPad view is messed up.
iPhone Output (okay)
iPad Portrait Output (messed up)
iPad Landscape Output (messed up)
What's happening in iPad?? Is it a bug or I'm missing something?
Thanks.
I have created a sample project.
Follow below steps to achieve your requirements :
Drag one horizontal Stackview in to your interface builder
set it's constraints like : top,leading, =trailing and fixed height
Drag and drop three labels in to it and select all together and set one constraint : Equal width
now select second or middle label and from attribute inspector click on + button beside installed and select Regular for both width and height. It will add regular,regular variation and uncheck the checkbox for that R,R variation. Refer below screen shot for better understanding,
And you are done! now you your center label will not show in iPad and every label will be displayed in iPhone!
See below result screenshot of iphone and ipad in my case!
iPhone :
iPad :
Update :
If you want two to hide label in iPhone and show in iPad then add one more variation : Compact Width Regular Height for middle label and uncheck the checkbox to uninstall. Refer below screenshot,
It seems you are hiding one of the labels on iPhone using the "installed" checkbox in Interface Builder. Using the "hidden" checkbox instead seems to solve the problem. Which I guess is a bug.

Autolayout a view within a view

I'm trying to have auto layout for my ios application but for iphone 6s the border is too small I've tried using pin and alignment constraints but it doesnt look right. The iphone 6s plus looks fine though. The only problem I have is the iphone 6s. The third image is what I have right now which is the view has is horizontal and vertical in container.
It looks like you're using fixed dimensions for the cells and the inter-cell spacing. Using a UICollectionView is probably overkill for this example, because you'll always have 9 squares for Tic-Tac-Toe. If that's the case, then you can do the following, assuming that the squares are UIButtons and they're contained in a plain UIView:
Constrain one cell's height and width to be 1/3rd the view's height and width. You can do this in the storyboard by adding height and width constraints that are equal to the superview's, but with a multiplier of 0.33.
Constrain all other cells' heights and widths to be equal to cell #1's.
For the borders, use User Defined Runtime Attributes to add a border, like this:

UIImageView sizing in AutoLayout + Size classes for all devices

I'm working on app and will for 1st time use auto layout/size classes. Today my first day learning it and I understand constraints now and how to place the images where I want them to be on every devices from iPhone 4s to iPad PRO.
As my main storyboard in Attributes inspector i'm using INFERRED size. In show Assistant Editor, Preview, i'm using all device sizes.
In my inferred storyboard i'm using a UIImageView size 170 Width, 230 Height. Then I use AutoLayout to make it center of every device screen in preview.
Now the issue is this UIImageView covers HALF of the size of iPhone 4s preview but only about 1/5th the size of iPad PRO. How do I alter the size of each UIImageView to the size that I want them to be in each device without changing that centered position of each UIImageView in the preview devices?
You need to first set up your constraints properly and then choose the type of scaling you want.
Set up your constraints:
Click on the Pin icon |-[]-| at the bottom of the screen. Turn on all four orange I-beams. Set the four constants to zero.
Uncheck the Constrain to margins checkbox and click 'add 4 constraints'
Then set your scaling:
Click on the Image View you added to your View Controller.
In the Attributes Inspector on the right, choose your image.
Set the Mode of the View to Aspect Fill (fill entire screen cropping top/bottom or left/right as necessary) or Aspect Fit (letter box image so that entire image is shown uncrossed).
That should work
Maybe you can use a pending or proportion constraints instead of width and height constraints.

Why my UILabel 's AutoLayout not working

in storyboard I set view controller size iPhone3.5-inch
add constraints with UILabel
UILabel.text cannot show all,so i change view controller size iPhone 4.7-inch
so i tap UIlabel update frame , autolayout work, it all ok!this is iPhone 4.7-inch
now the problem coming,when i run in iPhone simulator iPhone 6, autolayout don't working, the label size only zoom, the width don't change longer。 and The following three images constraints width and height both 32,but in simulator iPhone 6 images size Look bigger,Why is this so? please help me ,very thinks
No matter iphone6 or iphone5 iphon6+ ,code here output 320, why...
-(void)viewDidLayoutSubviews{
[super viewDidLayoutSubviews];
NSLog(#"%f",self.view.frame.size.width);
}
As per your question if you want text should not display ... then all you need to do is set number of lines = 0 and set Line break mode to word wrap.
As you are working with label it does not require any height constraint.
If you are building your application with size class and using launchScreen.xib then you label won't zoom and if you are using launch image then you need to all splash screen image of exact size.
You can find out about size of splash screen in below url.
https://stackoverflow.com/a/26191308/4101371
I've added images of view with constraint and changes in properties of label.
result will be displayed similarly in device and simulator.
And if you don't want to display label in multiple lines then you can set Auto Shrink (Minimum font Size/ Minimum Font Scale)
Hope it will help you in solving your problem.
Don't you forget to set constraints for your arrow image?
Set trailing and top constraint with fixed height/width.
Set 'Autoshrink' property of your label to 'Fixed font size'
this prevents label from changing font size depend on it's frame
Recreate your constraint for images - it looks like it pins to superview, so in runtime it scales to the size of superview
Hope this helps.

Auto layout: Xcode 6: Centering UI elements

I'm using Interface Builder in Xcode 6 to make an app and am having trouble getting the text fields and button to centre on the screen for different size screens.
I thought it was a matter of selecting horizontal and vertical centering in container but it doesn't seem to be that when I try it in auto layout. Actually I've tinkered around a bit and I still haven't got it.
I just want to be able to see all of my button and text fields for any size iPhone screen and right now simulator is only showing part of these UI elements like this:
I also want to do this in storyboard and not in code as I'm not at the level of doing this in code yet.
Step 1: Make sure your size class covers all the iPhone screen at least in portrait view. So, change the size class to "wCompact hRegular".
Step 2: After setting the size class properly, add the UITextFields and UIButton to your storyboard. To me, it looks something like-
Step 3:
Before, you start adding constraints, you need to remember two things-
a. Your element(UITextField, UIButton, UIView or any component) needs to know its starting position unambiguously, and
b. Your element needs to know its size meaning, its height and width.
In this case, as you want to centre your elements, I am just assuming that it needs to be centred starting from 10 scale from the left edge and should end 10 scales away from the right edge of your iPhone screen. Now, that means, it's width will be different based on the screen size, but its height will be same.
So, I just add the constrains following way for the 1st text box-
Notice, in the size inspector, I set the text box's starting point, x and width in a way that it is 10 pt away from left edge and 10 pt away from the right edge. Don't worry, it's just simple math.
For the 2nd textField, I add the constrain, the same way-
Lastly, for the button, the constrains are following-
Now, you are good to go. Everything is centered.
By using your size class selector in the bottom of the storyboard window, set you sizes as any width and any height and then follow the below auto layout constrains. It will work for you.
First select the view you want to set the auto layout, and then select the pin option from the right bottom corner of your storyboard and then add the constrains as shown in above picture and click button Add 4 constrains
Repeat the process for all views and set the constrains as Fix the top, bottom, left and right constrains of all views except the last button that should be fix from top,left,right and fixed height.
You need to make use of the size class selector in the bottom of the storyboard window.
So for an iPhone 6 or 6 Plus in portrait you would choose a compact width and regular height like this:
And then you would do whatever auto layout stuff for the given device there

Resources