activityIndicatorWrapper

activityIndicatorWrapper

我试图使UIActivityIndi​​cator的大小与UIRefreshControl中的大小相同,因为有时我需要手动刷新屏幕,有时刷新数据而不拉动屏幕,所以我需要模拟 Activity 指示器。

 _refreshControl = [[UIRefreshControl alloc] init];
    _refreshControl.tintColor = [UIColor grayColor];
    [_refreshControl addTarget:self action:@selector(refreshItems) forControlEvents:UIControlEventValueChanged];
    [self.collectionView addSubview:_refreshControl];


    UIView *activityIndicatorWrapper = [[UIView alloc] initWithFrame:_refreshControl.frame];

    [self.collectionView addSubview:activityIndicatorWrapper];

    _activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    activityIndicatorWrapper.frame = _refreshControl.bounds;

    [activityIndicatorWrapper addSubview:_activityIndicator];
    [_activityIndicator startAnimating];
    [_activityIndicator autoCenterInSuperview];
    _activityIndicator.hidesWhenStopped = YES;

问题是,即使我将它们制成相同的框架,尺寸也不同。

最佳答案

我也尝试过这样做。我认为这是不可能的,尤其是因为我们看不到UIKit在幕后做什么。

10-08 05:29