0

I'm trying to create a webview with some data and an image (from a uimageview) that the app has previously modified. Data 'link' to webview has been easy. But the modified (and still not 'saved', because it's not necessary for the app) image hasn't got a path.

I've tried:

var imageToShow: UIImage!
imageToShow.image = modifiedImage

let stringHTML = "<body>\(data1)<br>\(data2)<br><imgstyle="width: 350px; height: 175px;" alt="" src="\(imageToShow)"><br></body>"// This shows app data, but not the image: \(imageToShow) is not correct

webViewToShow.loadHTMLString(stringHTML, baseURL: nil)

I'm new to swift (3). Thanks in advance.

2
  • Out of curiosity - why do you need a webview for this? Can't you display a simple UIViewController with two UILabels and an UIImageView? Commented Feb 28, 2017 at 19:23
  • @Losiowaty I want to create a PDF file with different types of data (labels, images). In my project there are a few more 'datas' (about 200), but I have only problems with the image. Commented Mar 1, 2017 at 0:54

1 Answer 1

1

To achieve what you are looking for, try following:

  1. Write the image to a directory. eg mofifiedImage.png
  2. Load UIWebView with html string with baseURL set to the directory where image is stored

    let stringHTML = "<\img src='mofifiedImage.png'>" webViewToShow.loadHTMLString(stringHTML, baseURL: nil)

  3. whenever image is modified reload the UIWebView

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you. I'm having problems with linking (html code) with the image. I will let you know how it ends. I was thinking of a way to do it without saving...
I'm having problems with linking (html code) with the image in 'Documents' directory (any idea?).
glad, I could help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.