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
Related
I am having a problem with my constraints for an alert view I am building in interface builder.
When the screen is an iPhone 5 size I want the leading and trailing constraints to compress the images and make is smaller, I have a 1:1 ratio constraint set here too. This works great so far. However when the screen gets bigger e.g. iPhone7+ or iPad I want the image to remain the same size (that is the size of the image in interface builder, the iPhone7 size canvas). I have tried setting a constraint on the width of the image using <= and then setting the leading and trailing constraints on the image to priority 750. This works for the bigger screens but now when I go back to the iPhone5 screen size it is broken because the priority on the leading and trailing constraints is less than that of the ratio. The image size remains unchanged. Seems no matter how I work the constraints I can only get the size working for a single scenario iPhone5 or iPhone6+. Has anyone had this kind of issue before? Any suggestions on how I can work the constraints??
Try exploring on size classes. Explore on this link. https://www.raywenderlich.com/162311/adaptive-layout-tutorial-ios-11-getting-started.
Basically by using this you can set separate constraints to a same element with respect to size classes(which in term refers to different sizes of device screens).
You can implement it this way. It works well for iPhones of all sizes.
There are 3 key points regarding the UIView containing the image
Set leading and trailing constraint as greater than or equal (>=)
Center the view horizontally in the superview. This constraint combined with the previous ones will result in the view staying centered even when the image won't be able to stretch anymore.
Set content hugging priority to required (1000).
I've got the below layout and I've got it working well on iPhones, landscape only.
The PickerViews are currently populated with an image array. Currently, I force resize the images in the PickerViews based upon device size by setting the PickerView row height and image height to what fits each specific device (iPhone 5 -7+). However, to work on an ipad, I need to expand the ImageView in the center.
When I change the hugging values to >= it allows it to grow too large and pushes the PickerViews out the side on iPhones, despite them having a 4nit margin to superview. I've tried playing with the hugging/compression priorities but I can't make any headway.
Each item is in its own stack view. What is the best way to go about this?
Layout Image
Did you add leading and trailing constraints to ImageView? As I understand you set the sizes to pickerViews?
Anyway, could you tell all constraints you have added? And how your elements should be resized on different devices(how can be compressed if there is not enough space)
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've got all my elements in the view and have added constraints to position them correctly on any device.
But when it's run on a 3.5 inch iPhone some of the bottom stuff is cut off and when it's run on a iPhone 6Plus there's a lot of extra space on the bottom.
How could I resize all the elements to look good on all devices?
This is a universal app to run on iPhone and iPad.
I guess you constraint an element as width equals 300...It's very bad for some elements that should fill (or fill percent of) the screen. I suggest you make percentage constraints. For example, make equal width to view, click Edit button and set Multipiler 0.6. It looks like this in storyboard:
make two constraints (trailing and leading for example) and make aspect ratio for your image, maybe this will help you.
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.