UIStepper moves out from screen, why? - ios

I have an UIStepper in tableView. It is in a container view, but that one has correctly set up, with constraints etc.
Any idea what is the problem?

You constraint for First UILable may having Expandable Width, which leads to move next three controller to move aside, eventually next controls moves its position by frame.x increasing.
You can stop first UILable to increase width by deleting Adjust width constraint. Alternate to change width, you can size down the font size and increase number of lines.
HTH, Enjoy Coding !!

I forget to add width constrain to UIStepper. It is not strait forward that it has a 94px width, it has to be specified.

Related

Change a custom view height based on the label height Swift

I marked the view inside a circle, the vertical line. .I want to increase its height when the right side labels height increases. The labels become multi line based on the content.Help me figure it out. Is there have any autolayout way to do it ?
Implement viewDidLayoutSubviews, inside it take the height of the UILabel and modify your line height based on it.

UIScrollView with multiple multi-line labels and AutoLayout?

Is there a way to achieve this? I have tried literally everything and nothing has worked for me yet.
So basically what i want to do is the following: I have a scroll view with some labels in it. All the labels get their text from a server and I have set their number of lines to 0 so that they change their height according to the amount of text. However, this does not affect the scrollview content size(even though my labels have constraints set up to the bottom,top,leading and trailing of the scrollview) and the labels go off screen and I am unable to scroll down. Can someone point me in the right direction to how I would set up my constraints, my view hierarchy and etc?
Any help is much appreciated! :)
Late, but this solved it for me:
Set leading (I have a 32pt inset), trailing and top constraints. The trailing will not actually seemingly do anything..
Make the trailing Greater Than or Equal to avoid localization alert.
Finally, add a new Equal Width constraint to the label matching the scrollview. Use the constant to subtract the required padding (I used 64 due to mirror my leading inset).
And voilĂ ! The Label will align correctly both in IB and in-app.
In Scrollview the last view's bottom constraint is so important. You should set its priority to 250 and put it to Greater than or equal.
Remember you should only change the bottom constraint of the last view, which in my case it's the continue button.
I would consider using UITableView instead, it has several benefits:
It allows for reuse of cells, if all the cells look the same
It manages recycling of cells when the number of values you're getting from the server increases (decreases memory pressure when number of cells becomes substantial)
It allows for more flexibility with the content (it's quite often for design to change last second or to evolve over the course of the project)
Most importantly, UITableView support auto sizing cells (as of iOS8), you need to specify the constraints between the label and the borders of the cell
There are several resources to start with:
http://www.raywenderlich.com/73602/dynamic-table-view-cell-height-auto-layout
https://www.captechconsulting.com/blogs/ios-8-tutorial-series-auto-sizing-table-cells
http://www.appcoda.com/self-sizing-cells/
Use a container view in a scrollView
Add constraints to superview (leading, trailing, top, bottom, height,width)
Make IBOutlet of constraints that you are going to update.
Add you all labels inside that view.
Update constrains/frame of your label so that it fits the text.
How much you increase the label height you should increase the container height too.
If the label count is not fixed use custom label class to add subview.
Perhaps you should need to understand how ScrollView works in Storyboard with autolayout.

Truncate UILabel before it runs into another UILabel dynamically

Basically, I have this situation:
Two UILabels in a UITableViewCell. They're both constrained to the top of the cell. One is constrained to the left of the cell, and one is constrained to the right of the cell.
There exists a change that the UILabel on the left can run into the UILabel on the right. Is there anyway to truncate the text x points before it gets to the UILabel on the right?
Right now, I handle this by giving the UILabel on the left an explicit width that ensures it will truncate before reaching the UILabel, but the explicit width is not dynamic based on screen size. If there is a larger screen size, it might not need to be truncated. I'm new to iOS development and am not sure how to do this.
The best way to achieve this is in auto-layout. Make sure the label on the right is a fixed size, you can even change it programatically if you need to accommodate to screen size. But the thing is this one needs a width constraint. The label on the left does not have a width constraint, instead do a horizontal spacing in front of it to the cell border and from it's trailing end to the start of the label view on the right. It will widen and shrink to fit the size that's left for it.

UIButton changing width when label changes

I'm writing a calculator app with a shift key. When the shift key is pressed, some of the UIButtons' labels should change. The problem is that when they do, the widths also change and, because of certain design constraints, other buttons will resize themselves too. How to I lock the width of a button (either pragmatically or in the storyboard builder) so that it will never change (regardless of the contents of the button)
Thanks for any help in advance.
Buttons, like labels have an intrinsic size that's set by the width of their text plus some padding. If you want them to have a fixed width, then in IB, just give each button an explicit width from the menu, Editor --> Pin --> Width.
Have you tried using [button sizeToFit]? Call it after you resize the subviews within and then you will likely want to apply some "padding" as this will size the view to exactly fit it's subviews.
UIView sizeToFit

Controlling scroll viewer's scroll distance

I'm placing 20 textblocks in scroll viewer, but it scrolling upto 7? I also want to control the scroll distance in get scrolled whenever my application starts?
Probably, you set Height of ScrollViewer to Auto and it don't fit to screen. Set it to Parent Height. I hope it will work than.
Can you put up your code? Also make sure you have done these two things
1) Place it in a grid.row and set grid.rwo height to *
2) Do not place the scrollviewer in a stackpanel

Resources