Textfield Connecting and Labels - ios

I have always had this problem and could never figure out how to solve it. My issue is that I want to produce a similar thing as the photo: Image
I want to be able to have text fields connect like this and be able to have a 'label' on the left while still being able to input on the right. Any help is greatly appreciated.

If I am not mistaken, I think that what you want is to have a label on the left and a textview on the right. The image you have supplied looks like the textViews and labels reside within a UITableView controller as static cells. What they have most likely have done here is simply extended the label from the left to the centre and the textview from the right to the centre, such that each takes up half the cell (and added constraints). Then you can set the text alignment to left for the label and right for the textview. The final thing you should do is get rid of the border of the textview, which can be found in the attributes inspector and is called Border Style. You want to set it to the far left option, like this:
As the background of the cell is white and the textview's also, you shouldn't need to change it, but if you do there is an attribute for that a bit further down that you can have a play with.

Related

Layout UITextField regardless of clear button X

I need to horizontally center layout a UITextField, however, since the clear button is part of it, the (text entry portion of) text field doesn't look centered - the clear button isn't always visible but it is taken into account when laying out.
In the image above, the UITextField is horizontally centered, however, without the clear button (X on the right) and with only search text, it doesn't look like centered.
A way I can think of, is to subclass UITextField and provide alignmentRectInsets, for inset on the right I would use clearButtonRect(forBounds:) to get the size of clear button, whose width will be the right inset for alignmentRectInsets.
Question:
Apple's doc specifically mentions that one should not call clearButtonRect(forBounds:) directly, so I'm feeling a bit nervous for doing it; However, from the doc it feels like Apple's intention is to let people not changing the rect, and in my case I'm just getting its size, I guess it's fine?
Is there any better way of achieving this? I know I can tweak edgeInsets, or give the text field a leftView, to make the text field looking centered; But they all need some hardcoded assumption for the size of the clear button.
Thanks!
You can make the UITextField Alignment settings as middle then it will work. Check the below image
You can control over here.It may helps to you.Thank you.

How can I style a text field in iOS (Swift)?

I am a beginner and just started learning iOS. I want to achieve this layout, using Swift:
When you drag a text field into your project, there's a number of styling options available in the Utilities bar in Xcode, that can help you style the shape, colour and other properties of your field. To achieve the look you want, you could use something like this:
Place a UITextField and a UIButton on your story board. Then select both items, and then go to Editor, Embed In, stack view. If they are one on top of the other, change the stack view orientation to vertical then they will be side by side as shown above. Next change the attributes of both in the attributes inspector to taste. You can change the attributes manually in code using textField.defaultTextAttrubutes = [ "the look you are going for"], but you should need to in order to recreate your example.
you can add a view container to your view, inside that container .. add a button and a textfield then add positioning constraints on them.
as you can see in the picture .. it illustrates the idea .. you can style it the way you want e.g. change the height of your textfield .. change its border style etc. the same with your button.
example
In order to add a border, you have to enter some specific information in the attributes inspector. Here is a snapshot of what you can use to create border radius if you want one, vary the thickness of the border, and select a color for the border. screenshot of attributes inspectorYou can vary the values to make the radius greater and the width thicker also, plus you can change the color. Pay very close attention to the spelling otherwise this won't work.

iOS: Combine two UIButtons to one UIButton

On the storyboard I have two UIButtons. In my UIViewController subclass I have one IBAction method for this buttons. One of this buttons has an image and hasn't got a title, another has the title but hasn't got the image. So, it's simply image that behaves as a button and ordinary button.
Both of this buttons call a method. The problem is that if I push one button, another doesn't highlight. Another problem that this buttons have padding and for me will be better if this padding will be touchable (I mean space between image button and title button to be clickable).
I know that I can subclass UIButton and make my buttons as I want, but maybe there is a way to make what I want without subclassing?
Thanks.
1)
Assign both buttons to properties.
When an IBAction fires, you can set one or both buttons to highlighted via those controls' "highlighted" properties, or via setHighlighted:.
2)
As for making space between the buttons touchable, set the alignment for the button graphic to left aligned or right aligned (the latter is what I've done in my example below) and these two separate buttons have edges that are touching.
3) Or...
You can cheat and have simply one button and put some space between your image and your button text, like this:
Yes, that's a whole bunch of spaces (which I've highlighted in green) before the word "Button".
Subclassing is a good thing. If you need a button with both an image and a title, then by all means create a subclass of UIButton that does what you want. You do that once, and then use it anywhere that you want. The alternative is to muck around with stacked duplicate buttons everywhere you want this look.
I found the most suitable variant for me and I think for all, who encountered the same problem. If you have one UIButton for image and another UIButton for text(title label), you can combine this two UIButtons to one Custom type UIButton. Then you can set image and title label text to this custom button. After that, use Insets to layout your image and title label.
For example, to set title label under image you must set Inset Left parameter as negative value and Inset Left parameter as positive value that is greater than image height. With Insets you can set proper image size too.
Using this way you don't need to handle highlight property changing by yourself.

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.

If a cell's detailTextLabel is empty how do I figure out where its right edge would be if it wasn't empty?

I'm using a table view for a form. When a row is tapped I add a text field to the cell (the cell is a value1 type) and the user can edit the contents of detailTextLabel. I position the text field so that it spans the distance from the right edge of textLabel to the right edge of detailTextLabel. Basically I set the frame of the text field over detailTextLabel except that it goes to the left as far as possible. Visually it's nice--there are no jitters when hiding/unhiding the text field.
It looks like this (without the green and red):
This works great when detailTextLabel has something in it. But when detailTextLabel is empty its frame is not yet defined. If you log it everything in frame is zero. So then I don't have a reference for placing the text field precisely over where detailTextLabel would be.
I could start figuring things out from the right side of textLabel and just go to the right until some number of pixels from the right edge of the cell. But, for example, what if there's an info button there? The nice thing about using detailTextLabel as a reference is that it's right edge is already correctly placed for that cell.
Any ideas?
You can always put a space (' ') instead of empty label. This way it will not be visible to the user, and you still get nice reference

Resources