iOS开发-UIRefreshControl下拉刷新

本文介绍了iOS中使用UIRefreshControl进行下拉刷新的方法,包括基本配置、回调处理及自定义加载图片等内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

下拉刷新一直都是第三库的天下,有的第三库甚至支持上下左右刷新,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];

实现效果不是很好:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值