我在iOS 6中看到了UIRefreshControl,我的问题是,是否可以通过拉下WebView来刷新它,然后让它像邮件一样弹出?我使用的拉比代码是WebView:
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self action:@selector(handleRefresh:) forControlEvents:UIControlEventValueChanged];
[rabih addSubview:rabih];发布于 2013-05-03 04:36:29
下面是使用下拉菜单刷新UIWebview的方法:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// Make webView a delegate to itself
// I am going to add URL information
NSString *fullURL = @"http://www.umutcankoseali.com/";
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
_webView.delegate = (id)self;
[_webView loadRequest:requestObj];
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self action:@selector(handleRefresh:) forControlEvents:UIControlEventValueChanged];
[_webView.scrollView addSubview:refreshControl]; //<- this is point to use. Add "scrollView" property.
}
-(void)handleRefresh:(UIRefreshControl *)refresh {
// Reload my data
NSString *fullURL = @"http://www.umutcankoseali.com/";
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[_webView loadRequest:requestObj];
[refresh endRefreshing];
}发布于 2015-05-07 22:11:14
在Swift中使用这个,
假设您希望在WebView中使用pull来刷新,
所以试试这段代码:
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];
}发布于 2013-04-08 01:46:09
我已经非常快速地将以下代码添加到我的代码中:
[webserver.scrollView addSubview:refreshControl]所以看起来UIWebView本身就有一个UIScrollView,你可以直接连接到它上。希望它对你有用。
https://stackoverflow.com/questions/13379815
复制相似问题