1、工程的建立
a、选择第二个(Greate a new Xcode project)
b、左边选择IOS中的Application,右边Singl View Application,最后next
c、在Product Name输入程序名,比如fistIOS
下面是代码
override func viewDidLoad() {
super.viewDidLoad()
setWebView() // 函数的调用,一定要写在方法内
}
func setWebView()
{
let webView = UIWebView(frame:CGRect(x:0, y:0, width:375, height:667))
let url = NSURL(string:"//www.greatytc.com/users/bdf11cce83a1/latest_articles")
let request = NSURLRequest(url:url! as URL)
webView.loadRequest(request as URLRequest)
self.view .addSubview(webView)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
注意在使用网址时一定要添加网址处理代码,否则无法显示
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
都添加完以后,运行结果如图