Display UILabels with input from UITextField - ios

Currently, I have a UITextField with an Add button at the end. The purpose of this textfield is for the user to enter word and for that word to be centered in a UILabel. Below is the visual :
I have the 3 UILabels embedded in a Stack View and each UILabel is hidden until user types something and presses Add button. Running simulator made me realize that if I keep one of them hidden it totally messes up the alignment of the other two. This is due to equal centering in the Stack View which made me question myself if this is right approach for what I want to achieve. I tried other distributions for the Stack View as well but no luck. Thoughts?

Related

How to add a button to the side and in between UIStackView rows

Imagine a horizontal stack view that contains two controls. Hopefully the type of controls doesn’t matter. Let’s say UITextFields. They’re set to take up 50 percent of the width via distribute evenly on their parent stack view.
Now imagine that I want to add more than one of these things. To keep things simple imaging two of them nested inside a vertical UIStackView. So now we have four text views each taking up a quarter of the parenting vertical stack view.
My question is this. For every pair of text fields, how can I get a button right in between the gap between that text field and the one below it, to the right. So for each pair one button to the right and under it right in the center of the gap between the top pair and bottom pair of text fields.
The idea is to make a control consisting of the two fields and the plus sign to the right and below. Hitting the plus sign would allow for the appending of an identical set of controls.
Thanks I’m advance. Sorry if this makes little sense.
I should add that the button should overlap the vertical space of both text fields.
Okay, thank you. I shall add an image. Imagine all of the fields besides those on the far right as text fields. The ones on the far right are buttons. Those buttons would add a new set of text fields, a pair to the left side.
I'm getting some ideas in my head since writing this originally. In my head you might have one vertical stack view. That vertical stack view would contain a regular UIView containing a pair of text fields and a horizontal stack view to the right. These would be nested inside a horizontal stack view where the text fields would be aligned to the top on the left and the center or bottom alignment for the button to the right.
Does that help?
When you hit the button on the far right, you'd get a new pair of text fields plus a new button.
Okay, I think I'm getting somewhere. Now all I have to do is work out how to do it entirely programmatically so I can add the views dynamically...
Have the buttons be in their own vertical stack view, with each button having the same height as the row of the control pairs, but the top layout margin of the buttons vertical stack view would be set to half the height of the control pair so that the buttons always appear in the middle.
In summary you'd have a horizontal stack view which contains two vertical stack views - one with the pairs of controls, and one with the buttons. you'd add a button and a pair of controls (which are arranged in a horizontal stack view of their own) on every tap on the button

How to have auto expanding text views all contained within a scrollable container in XCode/Swift/IOS

I have a storyboard view which consists of a textview which will display a variable amount of text which is a question. Below that I need to display 4 separate blocks of text - each is a possible answer for the question. They need to be able to react to being pressed and need to expand according to the answer they display.
Currently I have the question in a text view with the answers all being buttons. My question is what the best way of having all my text - question and each answer display within a scrollable view?
i.e. when the user scrolls the entire set of options move rather than just the text in the question or the text within one of the answer options.
Should I convert my answers from buttons to text views as well? If so what should I encapsulate them all in?
I would try selecting all the elements -- the textview and the four buttons --then go to the Editor menu and choose Embed in, then scroll view.
Editor > Embed in > Scroll view.
This will allow all your elements to scroll together as you desire.

Adding UITextField inline UILabel (Fill in the blanks)

I am trying to achieve something like this for iOS in Objective C.
The fill in the blanks(UITextField) should be inline, and should be able to have its own inputType.
Also, each View is a type of cell.contentView of a UITableViewCell.
My current approach is to find the length of string and also calculate the wrapping content length to the next line. Calculate the x's and y's for UITextField and add another UILabel after the UTextField
Is there any other approach other than this?
As EmilioPelaez says, this is not exactly an answer to your question, but a suggestion:
You can use a collection view with an horizontal flow for each "sequence" (i.e. UILabel-UItextfield-etc...)
That collection view has 2 kind of cell:
One with a uilabel with the number of line set to "1"
and the correct layout to fit the cell.
Another with a uitextfield and the correct layout
Coupled with:
My current approach is to find the length of string and also calculate the wrapping content length to the next line.
You may be able to easily adjust the width of the different cells, hide a uitextfield (if needed) and display a more dynamic "sequence" (if needed)
This is not exactly an answer to your question, instead it's a suggestion for a different interaction.
I think that instead of using inline textFields, you could use a UILabel with an attributed string, and in where the textFields would be, you add a different character with a different color that you can tap (For example, this character ✚).
When tapped, you can show an overlay with a text input, and once that input is completed, you update the label with the text (still tappable, and with a different color).
I think this answer might also be relevant: Detecting taps on attributed text in a UITextView in iOS
I think your solution of separating the UILabels and calculating their required positions is a good one for versions lower than iOS9, but if you can count on iOS, UIStackView can dramatically simplify the process for you. You can read more about the process in this tutorial:
UIStackView Tutorial
Good luck!

UIViewController with UITableView and TextField storyboard placement

This might be a simple question but using storyboard I can't seem to position my table, a message field and a button correctly. In the picture below, if it's positioned that way, only then do I get to see the text field and button at the bottom of the screen and the table view takes up the rest of the screen. If I drag the text field and button to the bottom and resize the table, the text field and button disappear and the table is cut off. Why is that? Is there a solution to this without doing it programmatically?
Easy solution is to remove all constraints then position them where you want them.
You'll find you get different effect when try to reposition items depending where you drag from for example double tap an item and nudge it with arrow keys or grab the middle to move it resizing via the corners.
But in my opinion it's easier remove all constraints from the view and then set them as you go.
Also you might want to consider using a container view for the table view and have a separate UItableViewController that way you can easily separate out that the tableview logic from the other ViewController. It will help stop things getting a little messy later on as project grows.

iOS: Stop ScrollView from making room when selecting textfield at top

I've scoured through several questions asking about how to prevent scrolling when selecting a first responder however nothing I find seems to work for this issue.
I have a UITextField above my table view at the very top of my page. When the user selects it (or when I do it programmatically) it drops down a bit, seemingly giving room for options such as "paste" or autocorrect (which I've disabled). I'd like to prevent this from happening.
I've tried setting the scroll position myself, which it initially does, but then it instantly jumps down a bit. Is there a way I can make the paste/edit bubble appear below the textfield (like it does with textfields in the header)? I'm thinking perhaps that will prevent it from jumping downwards, but I can't find information on this.
I'm completely stuck so any help is appreciated. Links, vague suggestions, whatever. Thank you.
Try embedding your text field in a scroll view the same size as your text field.
The reason why this should work is because when a text field becomes first responder, it only scrolls the scroll view that is its most recent ancestor in the view hierarchy. If it only finds the dummy scroll view, whose content size should not exceed its bounds size, then no scrolling should occur in either scroll view.

Resources