text and image as one scrollable entity
-
26-12-2020 - |
Pregunta
I need an undefined amount of text and one or more pictures to be scrollable as one entity. I'm quite surprised that this doesn't seem to be provided by default, I thought I've seen that several times before... I tried to google, but all I find doesn't fit. The images won't be wider than the screen, but in between lines of text.
I need something that let's me do something like:
image
textA
textA goes on
__ screen ends here, content goes on
textA goes on
textA goes on
image
image
textB
textB goes on
image
textC
The content for the text would come out of a plist, but I THINK I can predict it will be REALLY static, so I could just set the Text in IB and create a view for every content -.-. I've read about Web View, but as far as I got it, you'd need internet connection to make that work, and the app should work without any internet connection at all. Any suggestions or experiences concerning that?
Thanks a lot!
Solución
There different way to get things done:
- If you have static content and want a complicated layout and know how to do it in html you should go with UIWebview and a bundled html file and images and load it with something like:
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"MyStuff" ofType:@"html"]]]];
- You can also do a layout with UILabels and UIImageviews and arrange all of this onto one UIScrollview
- If it's more dynamic you should go with the latter, but you need to program sort of layout algorithms that handle different number/sizes of images, number/length of test paragraphs and so on.
Otros consejos
One option, as you mention, is UIWebView
.
It does not require a connection, since you can load a static HTML into it executing:
– loadHTMLString:baseURL:
By specifying a baseURL
that "points" to your bundle, you can also include images as resources in your Xcode project and have them displayed (by using <img src=... /img
in your HTML):
NSString* basePath = [[NSBundle mainBundle] bundlePath];
[_label loadHTMLString:text baseURL:[NSURL fileURLWithPath:basePath]];
You don't need an internet connection to make a web view work. Look at this method on UIWebView
:
- (void)loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL