LoginSignup
26
23

More than 5 years have passed since last update.

UIWebVIewをrefreshControlでリロードする(swift)

Posted at

webView.scrollViewにrefreshControlをaddSubviewするだけ。


class MyViewController: UIViewController, UIWebViewDelegate {

    @IBOutlet weak var webView: UIWebView!

    var refreshControl:UIRefreshControl!

    override func viewDidLoad() {
        super.viewDidLoad()

        addRefreshControl()
    }

    func pullToRefresh() {
        self.refreshControl.endRefreshing()
        self.webView.reload()
    }

    func addRefreshControl() {
        refreshControl = UIRefreshControl()
        refreshControl.attributedTitle = NSAttributedString(string: "読込み中...")
        refreshControl.addTarget(self, action: "pullToRefresh", forControlEvents:.ValueChanged)
        self.webView.scrollView.addSubview(refreshControl)
    }
}
26
23
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
26
23