swift iOS small control: UIWebView
发布时间:2020-12-14 06:24:17 所属栏目:百科 来源:网络整理
导读:UIWebView用来在App内嵌入Web页面。如下代码装入Apple.com官方首页在App内。 import UIKit class Page: UIViewController{ var c : UIWebView! override func viewDidLoad() { super.viewDidLoad() c = UIWebView() c.frame = super.view.frame view.addSubv
UIWebView用来在App内嵌入Web页面。如下代码装入Apple.com官方首页在App内。 import UIKit class Page: UIViewController{ var c : UIWebView! override func viewDidLoad() { super.viewDidLoad() c = UIWebView() c.frame = super.view.frame view.addSubview(c) c.frame.origin.y += 20 let url = URL(string:"http://apple.com") let ro = URLRequest(url:url!) c.loadRequest(ro) } } @UIApplicationMain class AppDelegate: UIResponder,UIApplicationDelegate { var window: UIWindow? func application(_ application: UIApplication,didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { self.window = UIWindow(frame: UIScreen.main.bounds) self.window!.rootViewController = Page() self.window?.makeKeyAndVisible() return true } } 关键代码在于: let url = URL(string:"http://apple.com") let ro = URLRequest(url:url!) c.loadRequest(ro) 构建URL对象和URLRequest请求对象,然后使用WebView的方法loadRequest发起请求,即可加载页面在WebView内。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |