swift3.0 uiwebview 如何自适应屏幕? 代码实现

swift3.0uiwebview如何自适应屏幕?代码实现如题,谢谢... swift3.0 uiwebview 如何自适应屏幕? 代码实现如题,谢谢 展开
 我来答
百度网友48b2b54
2016-10-11 · TA获得超过229个赞
知道小有建树答主
回答量:274
采纳率:50%
帮助的人:197万
展开全部
//
// ViewController.swift
// kids
//
// Created by yuexiaosheng on 15/9/4.
// Copyright (c) 2015年 Acrowdkids. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

@IBOutlet weak var wb: UIWebView!
@IBOutlet weak var bn_blue: UIButton!

@IBOutlet weak var bn_org: UIButton!

@IBOutlet weak var lb_msg: UILabel!
//var webView : UIWebView?
override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view, typically from a nib.
lb_msg.text = self.view.bounds.width.description
var width = self.view.bounds.width.description
var height = self.view.bounds.height.description
var fwidth = (width as NSString).floatValue
var fheight = (height as NSString).floatValue//屏幕高度

let sizew:CGFloat = CGFloat(fwidth/2)
let posy:CGFloat = CGFloat(fheight-40)

let sizewebview:CGFloat = CGFloat(fwidth)
let posywebview:CGFloat = CGFloat(fheight-60)

let registerBtn : UIButton = UIButton()
registerBtn.frame = CGRectMake(0, posy, sizew, 40)
registerBtn.backgroundColor = UIColor.orangeColor()
registerBtn.setTitle("注册", forState: UIControlState.Normal)
registerBtn.addTarget(self, action: "goList:", forControlEvents:UIControlEvents.TouchUpInside)
self.view.addSubview(registerBtn)

let registerBtn2 : UIButton = UIButton()
registerBtn2.frame = CGRectMake(sizew, posy, sizew, 40)
registerBtn2.backgroundColor = UIColor.blueColor()
registerBtn2.setTitle("登陆", forState: UIControlState.Normal)
registerBtn2.addTarget(self, action: "goList:", forControlEvents:UIControlEvents.TouchUpInside)
self.view.addSubview(registerBtn2)

var webView = UIWebView()
var url = NSURL(string:"http://www.baidu.com")
var urlRequest = NSURLRequest(URL:url!)
webView.frame = CGRectMake(0, 20, sizewebview, posywebview)
webView.loadRequest(urlRequest)
self.view.addSubview(webView)

}

@IBAction func goList(sender: AnyObject) {
var rootVC :ListViewController = ListViewController(nibName: "ListViewController", bundle: nil)

let NVC :UINavigationController = UINavigationController(rootViewController: rootVC)
NVC.setNavigationBarHidden(true, animated: true)

self.presentViewController(NVC, animated: true, completion: nil)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式