I am loading a text from an external API. The text is about 1000 - 3000 character.
Would a UILabel be good to hold this big text?
I already have my view wrapped inside a scroll view. So I was thinking of checking the height of the label when it has finished getting the text from the API, then calculate and set a new heigh on the scroll view.
I only want to display a static text, but with the function that will let the user to hold-copy a selection of the text.
Is a UILabel able to hold a text this big, or should I use a text view which has scrolling/editing disabled?
Thanks in advance,
According to Apple's Text Programming Guide for iOS, UILabel defines a label, which displays a static text string.
UITextField defines a text field, which displays a single line of editable text.
UITextView defines a text view, which displays multiple lines of editable text.
Although these classes actually can support the display of arbitrary amounts of text, labels and text fields are intended to be used for relatively small amounts of text, typically a single line. Text views, on the other hand, are meant to display large amounts of text.
For more information please check: Text Programming Guide for iOS
Related
I am very new to iOS Development. I recently started out on swift and learnt all the basics. This is my first app, so please bear with me if it is a dumb question.
I am trying to do the following.
Have a text input field, where a user can enter a persons name. We then display an image from our storage and a bio in a text view.
So, here's my problem sometimes, the bio text is quite large and is getting truncated. I tried the scrollable option in the attributes panel, but I do not want the image to stay there when I scroll down. I want the image to move up, similar to how it does in a webpage. Anyway I can achieve this or any resource you could point me to?
PS: I have tried using the scroll view, but I feel I am messing something up as it is not working as intended, and is truncating it.
The first picture is my main storyboard. The second one is the attribute panel for my text view.
Please let me know if you need any further details which I did not post here. I don't know what else to post.
Edit:
I am using Auto Layout.
Edit 2:
This is my View Controller Layout.
Edit 3 :
I have tried using a label with 0 lines like Beowulf suggested. But this is what happened.
Edit 4: Updated with the images of constraints and latest result.
Please note that the "Hero Text View" is just a label.
I don't think you need the container view for the text view. Mostly, what you need to do is set the height of the text view based on the content of the text view. Text views don't have an intrinsic size like labels or images. So you should create height constraint for the text view. Create an IBOutlet for it then set it programmatically. After you get the text for the text view say something like:
self.heroTextViewHeightConstraint.constant = self.heroTextView.contentSize.height
This will make it so your text view won't scroll, and, if you setup your scroll view correctly, it will resize to accommodate to fit all of its content.
If you truly don't want the text view to scroll you could just use a UILabel with lines = 0 and word wrapping, and you could avoid having to set any constraints programmatically.
I would suggest loading your text view with attributed text that include the image built-in. That way the image will scroll as part of the text scrolling with no effort from you.
Starting in iOS 7 NSAttributedString has a method that will let you load an RTF file or RTFD file (RTF file with embedded images). The method that creates the attributed string directly from a file URL has been deprecated in iOS 9, but the method initWithData:options:documentAttributes:error: is still supported.
You could create an RTFD file on your Mac that has the text and the image in it. Then drag that file into your project, load the file from your bundle into an NSData object, then use initWithData:options:documentAttributes:error: to load the data into an attributed string object that you can install into your text view.
I have a large text file and I need to show it continuously, like one can do in textview. However, the rendering of the text takes a lot of time in UILable/UITextView. I have tried working with TextKit to only render the portion of the text visible on screen but was unsuccessful. TextContainer's height need to be set depending on the content height for it to work and that is no better than using UITextView or UILabel.
Is there a way to only render the portion of the text that is visible on screen without using paging. Please share your thoughts on if that is achievable with high performance.
thanks
I am trying to achieve something like this for iOS in Objective C.
The fill in the blanks(UITextField) should be inline, and should be able to have its own inputType.
Also, each View is a type of cell.contentView of a UITableViewCell.
My current approach is to find the length of string and also calculate the wrapping content length to the next line. Calculate the x's and y's for UITextField and add another UILabel after the UTextField
Is there any other approach other than this?
As EmilioPelaez says, this is not exactly an answer to your question, but a suggestion:
You can use a collection view with an horizontal flow for each "sequence" (i.e. UILabel-UItextfield-etc...)
That collection view has 2 kind of cell:
One with a uilabel with the number of line set to "1"
and the correct layout to fit the cell.
Another with a uitextfield and the correct layout
Coupled with:
My current approach is to find the length of string and also calculate the wrapping content length to the next line.
You may be able to easily adjust the width of the different cells, hide a uitextfield (if needed) and display a more dynamic "sequence" (if needed)
This is not exactly an answer to your question, instead it's a suggestion for a different interaction.
I think that instead of using inline textFields, you could use a UILabel with an attributed string, and in where the textFields would be, you add a different character with a different color that you can tap (For example, this character ✚).
When tapped, you can show an overlay with a text input, and once that input is completed, you update the label with the text (still tappable, and with a different color).
I think this answer might also be relevant: Detecting taps on attributed text in a UITextView in iOS
I think your solution of separating the UILabels and calculating their required positions is a good one for versions lower than iOS9, but if you can count on iOS, UIStackView can dramatically simplify the process for you. You can read more about the process in this tutorial:
UIStackView Tutorial
Good luck!
I need to develop a text editor (UITextView) that will have multiple columns. I'm currently trying to accomplish this using Text Kit. Unfortunately, we can only use one TextContainer in UITextView (textContainer property).
I've seen a lot of implementation rendering text UITextView with multiple columns bit our requirement is different since it has to be editable. Multiple UITextViews does not work since we need to properly adjust the text position and cursor to overflow from/to the previous/next column.
Has anyone achieved this already?
In my app I have a "summary" paragraph that based on data an user actions in the app changes what it displays. The issue is it displays both regular text and clickable text (like a button) in the same sentence and line. The app will have a series of if else statements and based on the results of these the text that will be displayed is determined, but how do you make some of the text a button tied to an action and some of the text a plain label? Any and all help is appreciated!
In iOS 7, buttons look like blue text. I would suggest taking advantage of that fact.
I would use AutoLayout, and create your fields with constraints that put a very small amount of space between each label and button in your line of text/labels, with a vertical constraint on all of them that aligns their leading to match.