WebView 앱에 아웃렛 변수와 액션 함수 추가하기

Posted on 2021-09-05 by GKSRUDTN99
Swift&Xcode Xcode WebView

WebView의 아웃렛 변수 추가하기

1. Assistant를 열고, TextField에 대한 아웃렛 변수를 추가한다
  • Connection: Outlet
  • Name: txtUrl
  • Type: UITextField
2. Web View에 대한 아웃렛 변수 추가
  • Connection: Outlet
  • Name: myWebView
  • Type: WKWebView
  • WebView에 대한 아웃렛 변수를 추가하기 위해서, ViewController.swift 파일 상단에 WebKit을 import한다.
3. Activity Indicator에 대한 아웃렛 변수 추가
  • Connection: Outlet
  • Name: myActivityIndicator
  • Type: UIActivityIndicatorView

WebView의 액션 함수 추가하기

1. Go Button에 대한 액션 추가하기
  • Connection: Action
  • Name: btnGotoUrl
  • Type: UIButton
2. Site1 Button에 대한 액션 추가
  • Connection: Action
  • Name: btnGoSite1
  • Type: UIButton
3. 같은 방식으로 Site2, HTML, File Button에 대한 액션 추가
  • Connection: Action
  • Name: btnGoSite2, btnLoadHtmlString, btnLoadHtmlFile
  • Type: UIButton
4. ToolBar의 Stop 아이템에 대한 액션 추가
  • Connection: Action
  • Name: btnStop
  • Type: UIBarButtonItem
5. 같은 방식으로 Refresh, Rewind, Fast Forward 아이템에 대한 액션도 추가한다.
  • Connection: Action
  • Name: btnReload, btnGoBack, btnGoForward
  • Type: UIBarButtonItem