3.5inch screen cannot accommodate all subviews - ios

I have 3 labels .First one at the top of the screen, second in the middle and third below. I used both( size class(cW rH)+ autolayout)to layout the labels.The third label appears in all sizes expect the 3.5inch screen. Can autolayout and/or size class help me accommodate my third label in some way?.I know putting a scroll view or doing programatically will help me achieve what i want but just want to know whether the current iOS SDK is intelligent enough to cut this.

You have to use different constraint for each label.
Please check below screenshot to understand how to set constraint to each label.
May be it will help you to set labels.

I have Submit label as third label and I did following for it . Try using it and dont forget to click add constraint after doing it

Related

Autolayout UITextfield

I have been trying to achieve following layout in autolayout
I want to acheive this
may be i am doing something wrong due to which i am getting following result.I get this
can anyone correct me ?
This kind of layout is easily accomplished by using UIStackView, Please use UIStackView either in storyboard or in code.
Please check Apple documentation on it
https://developer.apple.com/documentation/uikit/uistackview?changes=_6
If you are using storyboard for Textfield then simply give leading and trailing to Textfield. Dont give the fixed width to textfield, it will work for all devices.
Same logic if you are setting textfield programatically. Dont give fixed width
As said above, use your element inside a horizontal stackview. Unfortunately, if you’ve a iOS target iOS 9.0, you will have to use another trick. Your stackview will become a normal view which will contain your elements to align. After that, you can the element width to be equal to their superview with the multiplier use.
Per example if you have 3 elements inside your view but you want that the first one being larger than the two others by setting the multiplier with a certain ratio like 2:4 for the first one and 1:4 for the last ones :-)

Handle the spacing between elements for a certain condition

I'm building a FeedViewController for my app.
This screen consists in a tableView (or a collectionView), that shows users' posts. A post always have a content, and it can include or not an image.
I was wondering what is the best way to handle the case when there is no image to display, how do you handle the height of the table view cell and assure that the spacing between each item remains the same?
What I've tried :
I created a subclass of table view cell and inside I added some constraints. Within the cellForRowAtIndexPath method of my FeedViewController, I added an "if statement" to check whether the postImageView.image is nil or not, and update the height constraint of the post image accordingly. The problem is, as you can see in the screenshot below, the spacing slightly differs from a cell with an image, to a cell without an image. I would like the spacing between elements to be exactly the same, no matters if there's an image attached to the post or not.
How would you guys solve that problem ?
Thanks for your help,
J.
If you use the autolayout then u need to give bottom and top constraints to buttonlabel. OR if you use the autoresizing then you need to fix the position of buttonlabel. #jellyfish6
I think you have given BottomConstraint for "Bottom Label" that is the reason why it is having different spacings.
I guess instead of giving bottom constraint provide it with top constraint or both and manage it with priority.

UIScrollView and variable text size

I'm creating an app with quite a lot of text. It will be of variable size, so I was wondering if there is a way to adapt my ScrollView to the size of the UILabel, not knowing in the IB what will be the number of lines of that label. I'm doing it from the IB, drag n dropping it, then I'm putting 4 elements inside : an image for the logo, a title, another image, and then the label.
My question is : how can I tell my ScrollView to adapt to the text ? With constraints ? In the code ? I'm sooooo lost with that scrolling thing…
I think I need a very very good tutorial about autolayout…
Here's some screenshots of my project
The project on simulator
The layout
Thanks a lot!
You have to add the constraints to your label so that it will always have the same spacing to the scroll view. Also, you will have to set your labels lines to 0.
Don't press Add Missing Constraints because it will probably set your height and you don't want that to happen. Use the Pin button to set the spacing to nearest neighbor.
These are the buttons you will have to use, they are bottom right.
First of all, press the one in the right and select All Views > Clear Constraints.
Then, select your label in the storyboard and press the button with a square Pin, here you will have to select everything until you have something like this with different values... Also click in the red lines so that you get a continuous red line. Don't check any of the boxes you see.
After this, you have to do the same process for your Scroller.
It should be enough. I will also need to know where your scroller is.
If you have anything else in your view, do the same.

Auto height setting for labels in iOS

I have previously worked in Windows phone and see that every control in windows phone has an Auto property, meaning occupy the size of the content.
I see that in iOS such a property does not exist. When there are dynamic data to be bound to a UILabel, I always need to calculate the height of the data and then assign to the UILabel. This takes a good amount of time and bit painful. Is not there an Auto property or am I missing anything here?
iOS has AutoLayout which is really helpful, get familiar with it.
Click on the Label
Click on the pin constraints button (little square button)
Add your custom LEFT, RIGHT, TOP margins or LEFT, RIGHT, BOTTOM margins
Click on "Add 3 Constraints"
Set number of Lines to 0 which means as much lines as view needs
Then you probably got warning lines, but you can solve them
Just click on fix constraints button (little triangle button)
Click update frames
UPDATE
Important: the answer to your question is to PUT NUMBER OF LINES TO 0 you can use that UILabel with 0 lines(which is autosizing) with frames and AutoLayout. AutoLayout is just a friendly suggestion that can be helful to setup views. Also put Line Breaking Word Wrap
Here you go also with some useful links for working with AutoLayout. AutoLayout is great because you don't care anymore what size is the screen, what orientation has the device at that moment. You just need to setup everything correctly and everything works amazingly but if your setup is wrong then AutoLayout might become your enemy. So start learning and experiencing right now.
Very good point to Begin learning AutoLayout
If Your are being lazy, start from video tutorial series
Great iOS7+ table view tutorial with autoresizing cells
Also check out this Stack Overflow discussion
You need to familiarize yourself with Auto Layout:
Auto Layout dynamically calculates the size and position of all the
views in your view hierarchy, based on constraints placed on those
views.
Just give top, left and right constraints and make label's numberOfLines to 0. That's it. Label's height will resize automatically.

Autolayout for button to bottom

I try to adapt my app for the 3.5 inches iPhone, but currently I have a problem, because I don't really get how to use the constraints to get what I want.
This is what I have for 4 inches:
This is what happens, if I apply 3.5 inches Form Factor:
But this is what I would like to have, managed by constraints:
Thank you very much in advance.
Regards.
I Think you need add constraint on all three objects
Do following steps
1). First add three constraint to top image view
I am attaching the image for that
In this image you need to give value according to your requirement
as i understand from above image i am giving the 20 from top and 0 from left and 0 from right
then click on the Add constraint button as you see in bottom of the image
2). then add constraint on take a note button in the same way that you have added from first
3). add constraint on last button
Add this constraint to your button.
You need to apply autolayout constraints on both note and save button along with imageView so when u open your app in 3.5 or 4 inches it will adjust and fit your component as per your size. You could also go for RESET TO SUGGESTED CONSTRAINTS if you are not able to understand on how to apply and for more on autolayout you could check out this tut

Resources