有人可以帮我解决如何将嵌入式URL加载到UIWebView的问题吗?该URL可以是Youtube的URL或加载任何页面的简单URL。
答案 0 :(得分:1)
这么简单,这是code for youTube:
NSString *embedHTML = @"\
<html><head>\
<style type=\"text/css\">\
body {\
background-color: transparent;\
color: white;\
}\
</style>\
</head><body style=\"margin:0\">\
<embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
width=\"%0.0f\" height=\"%0.0f\"></embed>\
</body></html>";
NSString *html = [NSString stringWithFormat:embedHTML,@"http://www.youtube.com/watch?v=qe39vPFabuA", 64.0, 64.0];
[webView loadHTMLString:html baseURL:nil];
如果您必须使用 UIWebView
加载某些网站,请使用此功能:
NSString *urlAddress = @"http://www.google.com";
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[webView loadRequest:requestObj];
只需在viewWillAppear中或根据您的要求添加此方法。