Swiftでは、これを使用します。
WebView でプルして更新したいとします。
だから、このコードを試してください:
override func viewDidLoad() {
super.viewDidLoad()
addPullToRefreshToWebView()
}
func addPullToRefreshToWebView(){
var refreshController:UIRefreshControl = UIRefreshControl()
refreshController.bounds = CGRectMake(0, 50, refreshController.bounds.size.width, refreshController.bounds.size.height) // Change position of refresh view
refreshController.addTarget(self, action: Selector("refreshWebView:"), forControlEvents: UIControlEvents.ValueChanged)
refreshController.attributedTitle = NSAttributedString(string: "Pull down to refresh...")
YourWebView.scrollView.addSubview(refreshController)
}
func refreshWebView(refresh:UIRefreshControl){
YourWebView.reload()
refresh.endRefreshing()
}
Objective-C では、これを使用しました。
- (void)addPullToRefreshToWebView{
UIColor *whiteColor = [UIColor whiteColor];
UIRefreshControl *refreshController = [UIRefreshControl new];
NSString *string = @"Pull down to refresh...";
NSDictionary *attributes = @{ NSForegroundColorAttributeName : whiteColor };
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:string attributes:attributes];
refreshController.bounds = CGRectMake(0, 0, refreshController.bounds.size.width, refreshController.bounds.size.height);
refreshController.attributedTitle = attributedString;
[refreshController addTarget:self action:@selector(refreshWebView:) forControlEvents:UIControlEventValueChanged];
[refreshController setTintColor:whiteColor];
[self.webView.scrollView addSubview:refreshController];
}
- (void)refreshWebView:(UIRefreshControl*)refreshController{
[self.webView reload];
[refreshController endRefreshing];
}