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...
You need to set the whole frame at once. Setting the size of a UIView's frame directly does not work.
var newRect = mainWebView.frame
newRect.size.width = self.view.frame.size.width
newRect.size.height = self.view.frame.size.height
mainWebView.frame = newRect
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.