UIRefreshControl incorrect title offset during first run and sometimes title missing

前端 未结 8 936
自闭症患者
自闭症患者 2020-12-04 15:46

The text is offset wrong by the first launch of UIRefreshControl... later sometimes the refresh text doesn\'t show up at all and just the spiny is visible

I don\'t t

相关标签:
8条回答
  • 2020-12-04 16:35

    I had the same problem, I did solve it by setting attributed text with space string to refresh control directly after init refresh control

    _refreshControl = [[UIRefreshControl alloc]init];
    [_refreshControl setAttributedTitle:[[NSAttributedString alloc]initWithString:@" "]];
    

    After that, setting new attributed text to refresh control was without any problems.

    [[self refreshControl] setAttributedTitle:[[NSAttributedString alloc]initWithString:[NSString stringWithFormat:@"Последнее обновление: %@", [dateFormat stringFromDate:[_post dateUpdated]]]]];
    

    UPDATE

    I noticed that problem come back when I use attrsDictionary:

    this code works fine

    NSAttributedString* attributedString = [[NSAttributedString alloc]initWithString:string];
    [[self refreshControl] setAttributedTitle: attributedString];
    

    and this make refreshControl's title appear directly after view loaded

    NSAttributedString* attributedString = [[NSAttributedString alloc]initWithString:string attributes:attrsDictionary];
    [[self refreshControl] setAttributedTitle: attributedString];
    

    I didn't find solution yet.

    UPDATE

    Finally found solution, after refreshcontrol init set attributed string also with attributes:attrsDictionary

    NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObjects:
                                     [NSArray arrayWithObjects:[UIColor appDarkGray], [UIFont fontWithName:@"OpenSans-CondensedLight" size:14.0f], nil] forKeys:
                                     [NSArray arrayWithObjects:NSForegroundColorAttributeName, NSFontAttributeName, nil]];
    [_refreshControl setAttributedTitle:[[NSAttributedString alloc]initWithString:@" " attributes:attrsDictionary]];
    

    so after that there is no problem to set new refreshcontrol's title.

    0 讨论(0)
  • 2020-12-04 16:36

    calling endRefreshing under viewWillAppear did it for me:

    -(void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
    
        [self.refreshControl endRefreshing];
    }
    

    Under iOS7 with a custom UITableViewController inside a UINavigationController

    0 讨论(0)
提交回复
热议问题