I want to show a paragraph of text. I have tried UILabel but this makes the text vertically aligned: it does not start from top. If I use UITextView and disable the properties selectable and editable it behaves like UILabel. Which component should I use?
You can use UILabel to TextView with NSAttributtedString.
Also you can also set your ULLabel or textview text attribute from storyboard .
Related
I am using storyboard to design my UIView. But I've stuck at the task: I have a multiline UILabel, UIView and UIButton. I want to make UILabel to wrap my button - the fist line of the text has a trailing constraint to UIButton another one to it's super view. And if my UILabel has no text I got a view at the bottom of label and I need to make this view trailing constraint to UIButton but if I got a free space - to it's superview.
Screenshot example:
I want to jump second line word after 'pyat' . Sorry for my poor english, hope that picture could help to explain my question.
Is it possible to make it directly in IB?
Perhaps instead of using UILabel you can try UITextView by using its textView.textContainer.exclusionPaths property to define a button container area to exclude.
Have a look at the sample code with a reported issue for selected and editable case.
As I remember you must limit the app deployment target minimum to 7 or later if using this property.
Hope that helps!
What you want to do is not supported out of the box and will take a lot of work because it will require subclassing UILabel and overriding drawRect.
An easy solution is to set attributed text on the label and use that to format the specific word to look like a button. UILabel attributed text supports hyperlink like behavior.
Is it possible to change the UILabel text by user interaction? Or is it necessary to do it with a UITextField element?
Can you tell me the way of doing it?
I don't think that it's possible to change the UILabel text by user interaction.
I would use a UITextField with no borders to make it look like a UILabel. You can do this using the Attributes Inspector in the storyboard.
UILabel is inherently not editable, from the class reference:
The UILabel class implements a read-only text view.
You would have to use a UITextField or a UITextView - UITextView being more like a UILabel than a UITextField.
From the UITextView class reference:
The UITextView class implements the behavior for a scrollable, multiline text region. The class supports the display of text using custom style information and also supports text editing. You typically use a text view to display multiple lines of text, such as when displaying the body of a large text document.
- How to increase the height of the text field in order to accommodate multiple lines, as the text field grows accordingly.
- I want something like multiple line attribute in android.
UITextField not supporting multiple lines text place UITextView in the place of UITextField.
Look at UITextView and not a UITextField.
Use HPGrowingTextView for iOS for multiple lines textview
How can I add a button in textview? for example..
textView.text=#"text here\n\n text also here\n\n text here aswell";
How can I add a button after each "\n\n" or along the text?
You can create a object of UIButton and add it as subview to yout textview.
You need to preset the frame of the button So the text must be statis and you must know the position of the button in advance.
so your \n\n creates a paragraphs
You can do it without static text just split your text in separate textviews by \n\n, add them to your scrollview. You have to measure your text paragraphs height to set the right frame for textviews and leave gaps for buttons. I would rather use tableview so you dont have to worry about that. Add buttons in between, it is doable.
you may reconsider adding buttons along the text this way (you can but it is really convoluted way of doing things), use webview for that as already stated here by others
I am making my first text field, and I am looking for more of a text area that the person can fill out. Xcode disables for me the ability to extend it to more than one line. Is it possible? If so, how do I do that?
Thanks!
You want a UITextView, which is an editable field that can accomodate more than one line of text.
A multiline UITextField is implemented by the UITextView and making sure its editable property is set to YES.
The UITextView class implements the behavior for a scrollable, multiline text region.