【问题标题】:Making UIActivityIndicator be the same size as the on in UIRefreshControl使 UIActivityIndi​​cator 与 UIRefreshControl 中的 on 大小相同
【发布时间】:2015-07-02 14:45:48
【问题描述】:

我正在尝试使 UIActivityIndi​​cator 与 UIRefreshControl 中的 on 大小相同,因为有时我需要手动刷新屏幕,有时无需拉动屏幕即可刷新数据,因此我需要模拟活动指示器。

 _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;

问题是尺寸不同,即使我把它们做成同一个框架..

【问题讨论】:

    标签: ios uiactivityindicatorview uirefreshcontrol


    【解决方案1】:

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

    【讨论】:

    • 你是怎么解决的?到目前为止,我跳过了手动刷新,因为它更麻烦
    【解决方案2】:

    y: -105改成你想要的,也许先试试y: 0

    运行这个然后尝试拉动刷新,希望这会有所帮助

        private func setupTableViewRefresher() {
            let refreshControl = UIRefreshControl()
    
            refreshControl.attributedTitle = NSAttributedString(string: " ", attributes: [NSAttributedString.Key.foregroundColor: UIColor.clear, NSAttributedString.Key.font : UIFont.boldSystemFont(ofSize: 56)])
            refreshControl.transform = CGAffineTransform(scaleX: 0.6, y: 0.6)
            refreshControl.backgroundColor = self.view.backgroundColor
            
            // refreshControl.addTarget(self, action: #selector(refreshTableView(_:)), for: .valueChanged)
            
            tableView.refreshControl = refreshControl
        }
    
        private func createSpinnerFooter() -> UIView {
            let footerView = UIView(frame: CGRect(x: 0, y: -105, width: view.frame.size.width, height: 100))
    
            let spinner = UIActivityIndicatorView()
            spinner.transform = CGAffineTransform(scaleX: 0.9, y: 0.9)
            spinner.center = footerView.center
            footerView.addSubview(spinner)
            spinner.startAnimating()
            
            return footerView
        }
    
        override func viewDidLoad() {
            super.viewDidLoad()
                    
            setupTableViewRefresher()
    
            tableView.isHidden = false
            tableView.tableFooterView = nil
    
            tableView.tableFooterView = self.createSpinnerFooter()
        }
    

    【讨论】:

      猜你喜欢
      • 2012-06-21
      • 2011-02-07
      • 1970-01-01
      • 2012-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多