我正在Swift
中编写一个应用,我正在尝试使用iCarousel
html
我正在使用的UIWebView
页面加载图像预览。
现在问题是我无法预览html页面,但是当我尝试预览图像时,我可以预览它。
这是我的代码
func carousel(carousel: iCarousel, viewForItemAtIndex index: Int, reusingView view: UIView?) -> UIView {
var webView : UIImageView!
let webV:UIWebView = UIWebView(frame: CGRectMake(0, 0, 200, 200))
webV.loadRequest(NSURLRequest(URL: NSURL(string: "http://www.google.com")!))
webV.contentMode = .ScaleAspectFit
if webView == nil{
webView = UIImageView(frame:CGRect(x:0,y:0,width:200,height:200))
webView.contentMode = .ScaleAspectFit
}else{
webView = view as! UIImageView
}
webView.image = UIImage(named:"left-arrow.png")!
return webView //returns image carousel
//return webV //returns blank carousel. I want this to work !!!
}
如何实现此功能?
修改1
我可以预览图像
附上carousel.type = iCarouselType.Linear
个屏幕。
这就是它的外观
但我希望它能用于任何其他旋转木马
carousel.type = iCarouselType.CoverFlow
这就是我得到的
这是我回国时得到的UIImageView
答案 0 :(得分:0)
我使用WKWebView
代替UIWebView
这是工作代码
let webV:WKWebView!
webV = WKWebView(frame: CGRectMake(20, 20, 200, 200))
var url = NSURL(string:"http://www.fb.com/")
var req = NSURLRequest(URL:url!)
webV!.loadRequest(req)
return webV
另外,请确保通过添加以下行
导入WebKit
import WebKit