I want to make this kind of text field in my application. Could you guys suggest how to create a text field like the ones shown in this picture?
What you're showing in the picture is table view cells, not simply text fields. Do you want table view cells that look like that? You want table view cells if your view controller is a UITableViewController. You can easily create a nib file (cmd-n, iOS User Interface, Empty, name and save it), drag out a Table view cell from the asset library, and then drag in the label and text field (see below) into the cell.
If you don't have a UITableViewController, you could just put a UILabel (for the 'Apple ID' or 'Required' part) in your view controller's view in interface builder and then add a regular text field, write its placeholder in the Attributes Inspector, and then choose the 'Border Style' (again, in the right Utilities panel in Xcode) on the far left, the one that looks like dashed lines (this is 'no border')
Use UITextBorderStyleLine from UITextBorderStyle enum
ObjC
typedef enum {
UITextBorderStyleNone,
UITextBorderStyleLine,
UITextBorderStyleBezel,
UITextBorderStyleRoundedRect
} UITextBorderStyle;
Swift
enum UITextBorderStyle : Int {
case None
case Line
case Bezel
case RoundedRect
}
Edit:
The first image was different from the new one. So, the picture shows that It's a table view(as you can see there's header for each section) that the first section contains two text fields. The two text fields' border style is UITextBorderStyleNone.
Use Eureka! It's an open source library available on Github - https://github.com/EurekaCommunity
It's really useful for creating form-based table views like the one you've described above.
Related
I have a custom #IBDesignable UIButton. I use several of them on a screen in the Storyboard file and they are central to the whole flow of the app. They all appear in the Guide as "Button":
"Button"s in guide
Seeing the actual title would be a whole lot easier in managing the Storyboard (although of course has no effect on actual runtime). I'd like to set the title to an #IBInspectable label text I'm using:
Their attribute Inspector
I'm using my own label text instead of the regular button title because it's layout and format is special. If I set the button title it shows up in the middle over the real title.
Ideally I want to set the guide "title" to my label. I couldn't find anything anywhere on how to do this. Otherwise, is there some work around trick to use the Button Label? Keep in mind this is just to make the Storyboard less confusing for others to see and use.
Thanks!
You can always slow double click each button (in the Document Outline (the left pane (your first picture))). It'll let you rename it right there.
By "slow double click" I mean, click to select, wait a sec, click again (without moving the mouse).
I'm only familiar with The Document Outline automatically naming things when you provide referencing outlets (control dragging to a .swift file). They'll take on the names of the variables you're dragging them to (even so far as formatting camel case with spaces and caps for you). Otherwise, in your case, you're probably going to have to manually name each one.
You can "name" your elements by filling in the Label field in the Identity Inspector pane:
As you see, I have a normal UIButton, and I put "Button One" in the Label field... so it shows up as "Button One" in the outline pane.
I need help in string formatting in iOS UITextView. I have a textView, for now it`s editable. Now I want to add a few strings. they should be like header and user must be able to type only under it, and when he press ENTER or DELETE line sting should change their position, so at the end it should look like
Header 1(with color not editable)
/* user can type here
*/
Header 2 (with color not editable)
/* user can type here
*/
I think i need to use delegate and attributed string or something,
but I can`t figure it out. HELP please
The best way to achieve this is to make two labels and two text views on top of a scroll view. like
The heights of two text views can by dynamic depending on the text length. And in this case you can avoid endless IF conditions as you would need to put everything in a single Text view.
The advantage of this approach is the label text format will be very easy to set, you can simply set the attributed string in the storyboard.
I want to create several controls just like the ones below the date time picker in the alarm app. They look like label controls, but they have a title on the left, the currently selected data value on the right, and an arrow all the way to the right. The Snooze control does not have an arrow, but I believe it is the same control. What type of control would I use to do this?
Any samples out there for this in Swift?
Thanks in advance.
It sounds like you are talking about different styles of cells of a table view.
The first control you mentioned (label on left, selected data value on right) is simply a table view cell with the RightDetail style and Disclosure Indicator accessory view.
The control with the switch is not a default cell style so you will have to make your own custom Table View cell. There are plenty of tutorials online that show how to make your own style of Table View cells. The item on the right is just a regular Switch.
What is the Document section when selecting the Identity inspector in any view.
Specially what are these squares with different colors for?
The whole Identity section of the identity inspector exists to make things more convenient for you in Xcode.
The Label field identifies the UI element in Xcode.Suppose you have three text fields in your window. Giving each text field a different label makes it easier to identify each text field.
Here is an example, create two UIViews in Storyboard, and use Label to identify each(Clarify: You can't refer to UI element by its label, Label is just for convenience):
The color label looks quite similar to color labels in operating system, but I haven't figure out how to use it in Xcode yet.
The note section give an attributed string with a key of userComments to the storyboard file. For the usage of note section, this post may helphow-to-add-copyright-information-to-a-nib-file
Is it possible to add a text link into a TextView? I want the link to perhaps behave like a button, where I can assign an action to it.
EDIT: When I say assign an action, I mean actually giving it something in the code. I'm wondering if it's possible to dynamically add a "button" into text that I can assign a coded action to.
Live scenario
Think of something like a dictionary app. Maybe the definition of one word uses another word that you might not know the definition of, so being able to click on that word to instantly search it rather than having to type it in would be a nice user friendly feature. It seems rather unlikely, though, I guess.
I would recommend using NIAttributedLabel from Nimbus, an open source iOS library. You can specify text ranges that are links, and you get delegate messages sent when a user taps on it.
Main Nimbus site: http://nimbuskit.info/
NIAttributedLabel docs: http://docs.nimbuskit.info/interface_n_i_attributed_label.html
in the inspector, go to the Text View Attributes tab then make sure "Detect Links" is checked.
Yes you can. Add the URL into the text view, then open up the Attributes Inspector. You will see an option in there to detect links.
I know of a way, but its a LOT of work. First, you have an NSAttributedString that you have the text view display. Second, attribute the range of text you want to be the button. Third, assign a tap gesture recognizer to the text view and in the method called by the recognizer, you'll use core text to determine if the tap happened over the range of text that represents the buttons.
Heres how youll use core text: create a framesetter with the attributed string. Create a frame from the framsetter with the shape of a square that is the frame of the text view, inset by the padding of the text view. The frame will allow you to get the y origins of every line in the text view and and once you know what line the tap happened on, you can use the line to then figure out exactly what character was tapped on that line by giving it an x offset. Once you know character index on the line, you can add it to the beginning of the range of the line and get the index of the character within the whole string. Then you can check if its within the range of the text that is your button. If it is, you can then call a method to simulate a target action type behavior.
Ive explained the process of how to accomplish this and specified what kinds of core text objects youll need, ill let you look up the specific api details:
https://developer.apple.com/library/mac/documentation/Carbon/Reference/CoreText_Framework_Ref/_index.html#//apple_ref/doc/uid/TP40005304
You can also use my objc core text wrapper:
https://github.com/mysterioustrousers/MYSCoreText
What about CoreText? It Can draw many kinds of Text .