lundi 26 janvier 2015

XCode 6 iOS Swift - UIWebView size won't change

I am currently trying some iOS programming. I decided to go with Swift.


Everything is going fine, untill I try to use a UIWebView it won't change it's size to the screen size. I started app development on Android, but afaik there is nothing like relative sizes in iOS right?


Currently this is what my code looks like:



import UIKit

class FirstViewController: UIViewController {

@IBOutlet weak var mainWebView: UIWebView!

var urlPath = "http://www.google.com"


override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.

loadWebView()
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

func loadWebView()
{
var newRect = mainWebView.bounds

newRect.size.height = self.view.frame.size.height
newRect.size.width = self.view.frame.size.width

mainWebView.frame.size = newRect.size

let requestURL = NSURL(string:urlPath)
let request = NSURLRequest(URL: requestURL!)
mainWebView.loadRequest(request)
}

}


I tried different approaches with the above (giving de frame size to the mainWebView, but none work. Maybe it has something to do with the moment I give the commands to change size? Should I change the size earlier in the loading proces?


I also tried this:



mainWebView.sizeThatFits(self.view.frame.size)


But that didn't do anything either.


I would definitely appreciate all help!


Thanks in advance


Friso


PS. In the example I am using the values from self.frame.size, but also when using for instance 100 x 100, it just won't change the size...




Aucun commentaire:

Enregistrer un commentaire