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

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.

Related

Textfield Connecting and Labels

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.

StoryBoard Different screen sizes iOS

I'm trying to make an app. I prepared the ui with sketch app.And I export the ui , it is like this:
I add some text field and button to View
But when I use Auto Layout and constraints buttons and text fields are going to another place.I need the use them like in the picture.What should I do ? Do you have any suggestion ?
Thank You
Notice the red arrow at the top right of your second screen shot. That is telling you that your constraints are faulty. Until you fix them, you will not see your interface widgets in the desired locations.
In general, as long as you see a red or yellow arrow in that spot, you need to work on your layout some more. Do not attempt to run a project when Interface Builder shows you that red or yellow arrow; your results will be disappointing, to say the least.

Adding Spacing Constraints to Text Field

I have a simple storyboard with a text field. I want to add spacing constraints to this text field so that, when I rotate the device, the text field will auto stretch across the screen instead of stopping halfway.
I have looked at multiple tutorials and they all say to "Control-drag from the text field toward the top of the scene, ending in the empty space around the text field. This should reveal a pop-up menu from which you can edit the spacing constrains of the text field."
However, when I control-drag from the text field, I get this different pop-up menu:
This other pop-menu clearly does not allow me to do anything with spacing constraints. In fact, I can't click on it at all.
Furthermore, clicking "Editor > Resolve Auto Layout Issues" does not work, as the entire sub-menu is grayed out.
How can I correctly add a spacing constraint to this text field so that when I rotate the device the text field will correctly fill up the screen? Please try to refrain from answers that involve editing code, as I don't actually know any Objective-C and would like to make this effect in the storyboard.
NB - If it is at all helpful, I am following this tutorial. Albeit it is with Xcode 5, other tutorials on Xcode 6 suggest the same pop-up menu should exist.
You probably didn't activate auto-layout in the first place. Check the option in the right panel, under the File section:
It's a new behavior of IB
For example:
Now the contents of the menu depend on the edge of where you are trying to tie constraint:
or simple use tree from left of IB
Open the document outline to see the view hierarchy and try control dragging the text field to the View, it should show the options there. Your menu appears when you control drag onto the View Controller.

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.

Autosizing mask cant click center arrows

No doubt an obvious question for those in the know but I'm trying to make my view look nice (ie. expand vertically) on an iPhone 5. To do this I've been told I should have the autosizing mask set in such a way that all items are ticked, including the interior two arrows.
Trouble is on this particular view I can't tick those arrows, it won't let me.
Any ideas?
Here's what the image looks like:
In interface builder go to the pane on the right hand side of the screen. If you go to the 4th tab from the left:
You will probably see that you have the "Size" set to something other than "Freeform". If you set it to freeform you will then be able to set the "springs" on the view so that it fills it's superview.
Hope this helps.

Resources