How to embed local images in UIWebView?

前端 未结 1 1620
野的像风
野的像风 2020-12-17 02:53

Is there an easy way to embed local images in an UIWebView? For example, I would want to embed an logo.png image in the UIWebView, which I\'ve added to the Resources folder

相关标签:
1条回答
  • 2020-12-17 03:20

    yes it's very simple but, for others, remember to put "file://" at the beginning of your path

    for example:

    NSString *path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"png"];
    [myWebView loadHTMLString:[NSString stringWithFormat:@"<html><body><img src=\"file://%@\"></body></html>",path] baseURL:nil];
    
    0 讨论(0)
提交回复
热议问题