This repository has been archived by the owner on Mar 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
011 webViewをつかったiOSアプリの作り方
mgka edited this page Jan 7, 2016
·
1 revision
- Yosemiteが入ってるMac
- App StoreからXcodeをダウンロードする
ダウンロードに時間がかかるので事前にインストールしておくことをオススメします。
- Xcodeを起動してCreate a new Xcode projectをクリックします
- Single View Applicationを選択します
- Product Name に作りたいアプリの名前を入れます
- Organization Nameに'catal', Organization Identifierに'jp.catal'を入力します
- Languageにswiftが選択されているのを確認してNextをクリックします
- プロジェクトの保存場所を選択してCreateをクリックします
-
Main.storyboardを開いて、Object LibraryからWeb ViewをViewControllerに追加
-
UIWebViewをCtrlを押しながらクリックをして、ViewControllerにドラッグをしてdelegateを追加
-
Assistant Editorを開きます
-
webViewからCtrlを押しながらViewController.swiftにドラッグします
-
nameにwebviewと記入をしてアウトレットを追加します
- 下記のように記述をします
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var webview: UIWebView!
var targetURL = "http://catal.jp/"
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
loadAddressURL()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func loadAddressURL() {
let requestURL = NSURL(string: targetURL)
let req = NSURLRequest(URL: requestURL!)
webview.loadRequest(req)
}
}
-
ビルドして実行すれば完了です!
Copyright (C) Catal,Inc. All Rights Reserved.