0
votes

I have added UIImageView with view frame height and width and below that UIWebView has to be loaded. I am not sure how to implement this. I tried to add both in UIScrollView. Image is perfectly displaying but WebView not loaded. Adding UIWebView to UIScrollView is not good practice as its below screen, I need to make it in scroll. I am not using Storyboard, all through programming.

Please suggest what should be the best approach to implement this. Wether to use UIWebView in UIScrollView or if added then why it's not loaded. It comes blank.

func viewDidLoad(){

    var image = UIImage(frame: view.bounds)
    var webView = UIWebView(frame: CGRect(x: 0, y:  self.view.frame.height, width: self.view.frame.width, height: self.view.frame.height))
    var scrollView = UIScrollView()
    scrollView.frame =  CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height)
    scrollView.contentSize = CGSize(width: self.view.frame.width, height: self.view.frame.height*2)

    webView.delegate = self
    webView.loadRequest(URLRequest(url: URL(string: "http://www.google.com")))
    scrollView.addSubview(image)
    scrollView.addSubView(webView)
    self.view.addSubview(scrollView)

}

func webViewDidFinishLoad(_ webView: UIWebView){

}
func webViewDidStartLoad(_ webView: UIWebView){

}

Thanks

1
why not you show the codes on how you add your views?koropok
Like @koropok is saying, seeing code would help produce a better answer. We might have different suggestions if you're using nibs, storyboards, programmatic UIKit, or something else entirely.Andrew Sowers
Thanks for your input, I tried to put relevant code. Please have a look.Sonia
what seems to be the problem? i've tried with your codes and it seems to be working. uiimageview on top and uiwebview below.koropok
Is it? not at my end. Below UIImage, it's all blank..no webView.Sonia

1 Answers

1
votes

Your code is fine.

Please check if you are getting this error:

App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.

If you are getting this error, then add this in info.plist file:

enter image description here