zoukankan      html  css  js  c++  java
  • iOS开发-UIRefreshControl下拉刷新

    下拉刷新一直都是第三库的天下,有的第三库甚至支持上下左右刷新,UIRefreshControl是iOS6之后支持的一个刷新控件,不过由于功能单一,样式不能自定义,因此不能满足大众的需求,用法比较简单在UITableview和UICollectionview上面直接添加子视图即可使用。

    代码调用:

        self.refreshControl = [[UIRefreshControl alloc] init];
        [_refreshControl addTarget:self
                            action:@selector(refreshView:)
                  forControlEvents:UIControlEventValueChanged];
        [self.refreshControl setAttributedTitle:[[NSAttributedString alloc] initWithString:@"数据加载-FlyElephant"]];
        [self.refreshControl setTintColor:[UIColor redColor]];
        [self.tableView addSubview:self.refreshControl];
    

    刷新回调:

    -(void)refreshView:(UIRefreshControl *)control{
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [self.refreshControl endRefreshing];
            NSLog(@"原文地址:http://www.cnblogs.com/xiaofeixiang");
        });
    }
    

    当然如果有合适的图片我们可以覆盖加载的图片:

        self.loadingImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed: @"RefreshIcon"]];
        self.loadingImageView.center = CGPointMake(CGRectGetMidX(self.view.bounds), 30);
        [self.refreshControl insertSubview:self.loadingImageView atIndex:0];
        [self.refreshControl bringSubviewToFront:self.loadingImageView];
    

    实现效果不是很好:

  • 相关阅读:
    不做男女朋友,做蓝颜吧
    前端 让我尴尬~
    让IE6,IE7,IE8,IE9支持CSS3
    解决chrome不能显示12PX以下字号的字体问题!
    jQuery阻止冒泡和HTML默认操作
    Lazy Load, 延迟加载图片
    解秘微软雅黑
    FLV流媒体应用大攻略
    提升你设计水平的CSS3新技术
    分享下自写的HTML CSS规范
  • 原文地址:https://www.cnblogs.com/xiaofeixiang/p/4668815.html
Copyright © 2011-2022 走看看