且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

iOS 7 UIRefreshControl tintColor 不适用于 beginRefreshing

更新时间:2023-01-05 18:24:14

嘿,刚刚偶然发现了这个问题.

有趣的是,我通过先设置 contentOffset 然后调用 beginRefreshing 来修复我的代码

if(self.tableView.contentOffset.y == 0){self.tableView.contentOffset = CGPointMake(0, -self.refreshControl.frame.size.height);[self.refreshControl beginRefreshing];}

您可能希望为这个过程制作动画:

[UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^(void){self.tableView.contentOffset = CGPointMake(0, -self.refreshControl.frame.size.height);}完成:^(BOOL完成){[self.refreshControl beginRefreshing];}];

希望对你有帮助.

W

I'm trying to set a tintColor on my UIRefreshControl (building on iOS 7). I enabled refreshing for the tableViewController in storyboard, then in my ViewController viewDidLoad method i did the following:

[self.refreshControl setTintColor:[UIColor redColor]];

So now, when I pull to refresh, the color of the refresh control is red indeed:

I want my view to update automatically when it appears, so I did:

- (void)viewDidAppear:(BOOL)animated{
    [self.refreshControl beginRefreshing];
}

It didn't show the spinning wheel, according to https://***.com/a/16250679/1809736, I added

[self.tableView setContentOffset:CGPointMake(0, -self.refreshControl.frame.size.height) animated:NO];

to force show it. It shows it, but now it is back to default color:

If I try manually to pull to refresh afterwards, it is red.

I tried building it on iOS6 and it works as it should, so is that an iOS7 bug?

P.S.: it is not a problem with the simulator, I tried building it on device, same bug.

P.P.S: I built an example project, can you tell me if you have the same bug or if there is a problem in my code? Here is the link: http://d.pr/f/pGrV

Thanks a lot !

Hey just stumbled into this exact issue.

Interestingly I fixed my code by setting the contentOffset first then calling beginRefreshing

if(self.tableView.contentOffset.y == 0){
    self.tableView.contentOffset = CGPointMake(0, -self.refreshControl.frame.size.height);
    [self.refreshControl beginRefreshing];
}

You may want to animate this process:

[UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^(void){
    self.tableView.contentOffset = CGPointMake(0, -self.refreshControl.frame.size.height);
} completion:^(BOOL finished) {
    [self.refreshControl beginRefreshing];
}];

Hope this helps you.

W