What's the fundamental difference between them?
Is a UITextField that's not editable is effectively a UILabel?
Are those essentially the same?
UILabel: "The UILabel class implements a read-only text view."
UITextField: "A UITextField object is a control that displays editable text and sends an action message to a target object when the user presses the return button."
UITextView: "The UITextView class implements the behavior for a scrollable, multiline text region."
So:
labels are read-only
textfields are editable, and provide horizontal character seeking (not really scrolling) when the text is too long to display all at once. Generally used to input short text.
textviews are also editable, but provide vertical scrolling when the text is too long to display all at one.
In addition to the above answers, UITextView has selectable text. This means that you can copy it or get the device to speak the text.
UILabel - used for static text
rendering,
UITextField - is an input
field,
UITextView - is a multiline
input field
Finally Apple have covered this part in this amazing talk:
https://developer.apple.com/videos/play/wwdc2018/221/
The key takeways is as followed:
Also in addition to this: Only with UILabel you can get the Auto shrink feature, otherwise you should implement that (if needed)
Related
I have a text with multiple lines but at the end I want to add the phrase "more..." if the user press the more... word than the system it suppose to display the rest of the paragraph.
How can I do that?
one way is: use a UILabel to display a short text
put a UIButton under that with "show more" make settings to button to look like a UILabel
catch the action of the button, and remove the button and display a multines text and change the size of the UILabel.
This isn't the right approach for novice programmers, I hope I have helped with an idea.
You could use a UITextView that contains the limited text and add a UITapGestureRecognizer that when tapped, removes the gesture and adds text to the textview.
There is no particularly easy way, built-in way to do it. If you want to implement it yourself, your best bet is to use a UITextView instead of a UILabel. UITextView conforms to the UITextInput protocol, so when you detect a tap on the text view, you can use closestPositionToPoint: and related messages to figure out which part of the string was tapped.
Instead of doing it yourself, you could use TTTAttributedLabel or OHAttributedLabel. Both of these have built-in support for detecting taps on links. I haven't used either, so I can't advise you on which is better. There are probably other free solutions available, but those were easy to find.
I would like to have a default value for a NSTextField (or NSSearchField) and have this default value removed when the user clicks on it and set back when the text view loses the focus and the text field is empty. Like this:
It sounds like I should extend NSSearchField but I was wondering if there was an easier solution.
This functionality is in fact built-in; there's no need to subclass or otherwise extend NSSearchField.
That's the field's placeholder string. You can set it either in IB or via a call to setPlaceholderString:. Notice that this is a method of NSTextFieldCell. An NSTextField is the "public face" of its cell, and has cover methods for almost all of the cell's functionality. In this case, however, you need to send the message directly to the cell:
[[field cell] setPlaceholderString:#"Jumbo jets"];
Since NSSearchField and NSSearchFieldCell inherit from NSTextField and NSTextFieldCell, respectively, the process is the same for them.
Set the place holder string on the NSTextFields's NSTextFieldCell using
[[textField cell] setPlaceholderString:#"String Matching"];
I have a simple UITextField called month where I get users to simply enter the month they want via the keyboard that comes up. I would now like it for them to be able to use a UIPickerDate (or UIPicker) to make this selection instead. So when they press on the text field, a mini UIPicker appears and they make there selection, press anywhere on the screen and the picker disappears.
Does anyone know how to do this or has any suggestions? I am pretty new to programming and have looked at other answers but everyone seems to be referring to this being done in a table.
Thanks in advance!
You can set the inputView property on the UITextField to be an instance of UIDatePicker. When the instance of UITextField becomes the first responder, the picker view will be displayed with the standard keyboard animation.
// Assume that self.monthTextField and self.datePicker
// are properties of the view controller class
self.monthTextField.inputView = self.datePicker;
As for dismissing, that depends on the context. If there are more text fields to populate, consider adding a UIToolbar as the inputAccessoryView of self.monthTextField. Then you can add something like a UIBarButtonItem to make the next text field the first responder, similar to how the standard keyboard provides a Next button.
HI all,
I have designed a view in Interface Builder and connected correctly with its controller.
There some UILabel in it that are going to be filled with lot of text.
But, even if I have declared "word wrap" and set line to 0 in IB, I can display only first line. I notice that if I increase the height of the UILabel in IB, all the text display properly in multi line, but I cannot do that because text may vary.
Shouldn't the UILabel resize itself to fit all the text ?
Also, if I built the UILabel programmatically I can succesfully accomplish a word wrap, why cannot do the same with IB ?
What am I doing wrong ?
thanks
Leonardo
The only solution I found is to call sizeToFit programmatically on UILabel.
I wonder if there's a setting in IB to emulate this command.
Does anyone know how to wrap text in a UITextField? I am using Cocoa/Objective-C in Xcode for my iPhone project, and I can not seem to find a way to do this...
UITextField is meant for single-line text only. If you want multiple lines of text, then you'll have to use the UITextView class instead.
It's worth noting that UITextView inherits from UIScrollView, so if you don't want scrolling, you may want to stick with the UITextField and put up with the text being on one line... I once tried to subclass UITextView to make it like a multiple-line UITextField, but the UIScrollView made the task a nightmare—in the end I just went back to using a simple UITextField.