How to display a couple pages of text in swift ios - ios

I've got an information page which has about 3 pages worth of text to display.
What would be the best method to display all this text in an iOS application coded in swift?
I have been trying to do it with scroll view but I can't fit all the text into one label on one screen. And all the tutorials I'm following say to set the scroll view to the size of the label. But the thing is my text is so long that it would fill the screen several times.
How could this be accomplished so that no matter which device size screen it's being viewed on it will fit all my text and be scrollable vertically?
I can't seem to get it working with a scrollview :/

Put the content in an HTML file, and render it using WKWebView: https://developer.apple.com/library/ios/documentation/WebKit/Reference/WKWebView_Ref/index.html#//apple_ref/occ/cl/WKWebView

You can make a text view non editable.

I have this problem also.. Maybe you could use table view and add contents programmatically.. hope it could add to your imagination.

Related

How to have auto expanding text views all contained within a scrollable container in XCode/Swift/IOS

I have a storyboard view which consists of a textview which will display a variable amount of text which is a question. Below that I need to display 4 separate blocks of text - each is a possible answer for the question. They need to be able to react to being pressed and need to expand according to the answer they display.
Currently I have the question in a text view with the answers all being buttons. My question is what the best way of having all my text - question and each answer display within a scrollable view?
i.e. when the user scrolls the entire set of options move rather than just the text in the question or the text within one of the answer options.
Should I convert my answers from buttons to text views as well? If so what should I encapsulate them all in?
I would try selecting all the elements -- the textview and the four buttons --then go to the Editor menu and choose Embed in, then scroll view.
Editor > Embed in > Scroll view.
This will allow all your elements to scroll together as you desire.

iOS Swift trouble making detail page with embedded list and collection view

I am new in iOS development and Swift, I'm struggling creating a relatively simple detail page.
For now I have this layout made with interface builder:
The parts highlighted in red must have variable heights, every element is inside one big stack view which is inside a big scroll view.
The list of phone numbers is a label with Lines set at 0 so if I understood correctly that element will size itself correctly with the content.
I don't know how to implement the other two lists and how to make the whole layout to wrap onto the content.
To make you understand better I'm struggling because I'm used to make layouts in android and so making extensive use of the wrap_content option.
Thanks in advance
I think, you could use UITableView for image+text list and UICollectionView for images. If you are using constraints you have to add height constraints to your tableView and collectionView, but you could update those constraints from code with real heights.

How do I set a text view size in iOS to display large amounts of text

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.

RichText label or 'flow' layout for text in iOS (Xamarin/MonoTouch)

I am trying to repduce a similar sort of layout as in the screenshot below from the Digg app..
Notice that each list entry has a title in bold followed by the source, posted time and finally if there is enough space the start of the description line.
The question is what is the best way to achieve this in iOS? With some posts having longer titles than others I cannot simply say that the title label is 40px high and then place the Source label at 45 as the title will sometimes be longer and sometimes shorter.
Do I have to calculate the height of the label based on its contents before arranging the layout or is there some better way of doing this in iOS so that the views 'below' are automatically moved down?
Another alternative would be some sort of rich text label that I could add all the text to and have it automatically wrap round moving the later text down but I cannot find any sort of control in standard iOS / Xamarin (MonoTouch).
Any pointers would be greatly appreciated?
If you are using a storyboard the simplest way to achieve this result is to define different prototype cells. For example, you could define four different prototype cells, each one with a different layout like those shown in the example picture you provided. You can dequeue the appropriate cell based on the content you want to display so there is no need to adjust the layout in the code.
If you are doing everything in code, it's a lot more complicated since you have to build your own "layout engine" to adjust size and position of the views in your cell. You can have a look at XibFree or use MonoTouch.Dialog as suggested in the comments.

Implementing 'About' view in iOS using Xamarin Studio

How do I autosize Labels so they contain all the text, but don't take up any more space then necessary and stay vertically spaced the same whether the user is in portrait or landscape mode?
I am trying to implement a simple control that displays information about my app in paragraph form. It will have Headings, and Paragraphs. I am having problems correctly positioning things relative to each other and have them auto adjust as the user rotates their device and changes orientation.
In the example below, I have 4 labels. 2 are for headings and are bolded with larger font, 2 have standard font, but are long and have lots of text. I want to be able to have all the text visible on each label and have none cut off. I also, want all the labels as close as they can be to each other. So, their containing rectangles have to change based on all of the other label's height. So when I change from landscape to portrait orientation, the paragraphs may take 8 lines instead of the 3 lines it takes in landscape mode. I want the controls to shift to have the same amount of Vertical white space between each of them.
Here is a sample:
About this program
Thank you for downloading this app. It is designed to do some
wonderful things and will make all your wildest dreams come true.
Help
In order to use this program, use the tab bar at the bottom of the
screen to select what you want to do. When the view opens, slide the
items across the view until you are done.
I'll quote Mattt Thompson:
This is the type of thing TextKit was created for. Check out Wenderlich's tutorial for an easy start.
I followed the advice in Jason's comment and it works like a charm:
Try using a UIWebView and embedded HTML for your content. – Jason Oct
30 at 19:23
Thanks Jason !!

Resources