Why my UILabel 's AutoLayout not working - ios

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.

Related

Fixed Button Position Relative to ImageView in Xcode

In my project I would like to essentially 'Pin' a button to a certain position on an image. The imageView scales to the screen size from the centre and maintains its aspect ratio.
I am trying to make it so that each button remains over the chakras "coloured icons in centre of body". I need them to maintain a scale that is the size of the chakras and maintain their position over the chakras regardless of screen size.
Wanted Result
Current Result
Scaling Settings
Aspect Settings
Here's an example - you will want to play with the exact positioning, but this should show you the method. You can do everything using auto layout in Xcode.
I took one of your images, and edited it to remove the buttons, and used it as the image in a UIImageView filling the screen of a UIViewController
Then I created 7 small buttons, and added constraints to them width & height = 20, and Align Centre Y to Image View
The tricky part is to add a constraint to align the centre of each button to a fixed percentage of the UIImageView centre - and that will be trial and error until it looks right.
Here's how to set the constraint
here's the app running on the iPhone 12 simulator
and here it is on an iPad (12.9 inch)
and here in landscape
You can take parent containerView for each imageView and Button.
Please see the picture to this link for better understand.
https://ibb.co/dsTjxbw

IOS auto layout constraints

having trouble with my first app login screen...
it looks good on iphone 8 screen size
but when the screen is smaller - the images go off screen.
i use auto-layout with interface builder.
tried playing around with the constraints:
- spacing less or equal with high priority
- use a stack view
- autoshrink on the text label
- compression resistance
so far couldn't get the right set of constraints for it to work.
anyone?
Update following the comments:
these are my constraints:
and autoshrink on the label with "minimum font scale"
i want the the images will get closer to the text, and the text to shrink so they all will be shown in one line.
You need to anchor the images to the edges, then it will shrink the font size as long as you have set Autoshrink. Connect as the image below.
Basically, it is connected like this
|<-->image<-->label<-->image<-->|
Then set them images to fixed sizes, and let the label size itself.
You also need to position them on the Y axis.
I have done with this
The following result in iPhone 5s
and 8 plus

Autolayout - text field is vertically stretching when run in simulator

When I run my Swift app in an iPhone 6s simulator, the text field seems to be getting vertically stretched. The storyboard can be seen below:
The app running in the simulator can be seen here:
I am not sure how to prevent this. I would like the bottom text field border to be closer to the placeholder text. Manually changing the height of the text field in the storyboard has not worked. I have constraints from each side of the text field to the respective side of the parent view. The storyboards are set to iPhone 6s and the simulator is set to iPhone 6s, surely the storyboard content should look almost identical in the simulator. Can anybody offer any assistance on this?
Remove the bottom constraint of the textfield! It is causing the textfield to increase height when view gets bigger.
To increase the size of the textfield with the size of device, you should add one more constraint: Aspect Ratio.
There must be problem with the constraint. First set your textField contraint to center vertically, center horizontally or remove one of the constraint upper or lower one.

xcode auto resizing xib not proper on iphone 6s plus

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.

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.

Resources