在Swift中的iCarousel中预览UIWebView

时间:2016-07-11 10:26:23

标签: ios swift uiwebview icarousel

我正在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个屏幕。 enter image description here 这就是它的外观

但我希望它能用于任何其他旋转木马 carousel.type = iCarouselType.CoverFlow这就是我得到的 enter image description here 这是我回国时得到的UIImageView enter image description here

1 个答案:

答案 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