繁体   English   中英

无法从CSS档案载入图片

[英]Image not loading from css file

我设法在UIWebView中显示html,但是我的问题是图像没有显示在HTML中,尽管我的图像,css和javascript都位于同一项目文件夹中。

这是我的HTML:

<html>
    <head>
        <meta name = "viewport" content = "initial-scale = 1.0, user-scalable = no, width = 320"/>
        <link rel="stylesheet" type="text/css" href="site.css">
        <script src="site.js" type="text/javascript" />
    </head>
    <body style="margin:0;padding:0;">
        <div class="player"></div>
        <div class="controller">
            <div class="search"></div>
        </div>  
    </body>
</html>

这是我的CSS:

body{
    padding:0;
    margin:0;
}

div.player{
    width:320px;
    height:180px;
}

div.controller{
    float:left;
     width:320px;
}

div.search{
    float:left;
    height:40px;
    width:320px;
    background-image:url('search.jpg');
}

最后,我的Objective-C:

-(void)viewDidLoad {
    NSString *path = [[NSBundle mainBundle] bundlePath];
    NSURL *baseURL = [NSURL fileURLWithPath:path];

    NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];
    NSString *htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
    [navigatorWindow loadHTMLString:htmlString baseURL:baseURL];

    NSLog(@"%@",htmlString);
    [super viewDidLoad];
}

知道这里发生了什么吗?

确保将search.jpg添加到Xcode项目中。 我相信这是问题所在,因为它是本地html文件,而不是托管在服务器上。 希望这可以帮助。

background-image:url('search.jpg'); 你必须在这里给出完整的图像路径

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM