Add UIActivityIndicatorView into UIBarButton

后端 未结 6 1562
忘了有多久
忘了有多久 2021-02-01 03:00

How do I add a UIActivityIndicatorView spinner circle into a UIBarButton, so that when a user taps on one of those buttons on the navigation bar, they see a spinner while the lo

6条回答
  •  离开以前
    2021-02-01 03:56

    If you're trying to show the activity wheel in a navigation bar button (e.g. you might have a refresh button on your navbar) - you can create a new UIBarButtonItem with a custom view being the UIActivityIndicatorView:

    Objective-C

    uiBusy = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
    uiBusy.hidesWhenStopped = YES;
    [uiBusy startAnimating];
    [self.navigationItem.rightBarButtonItem initWithCustomView:uiBusy];
    

    Swift

    let uiBusy = UIActivityIndicatorView(activityIndicatorStyle: .White)
    uiBusy.hidesWhenStopped = true
    uiBusy.startAnimating()
    self.navigationItem.rightBarButtonItem = UIBarButtonItem(customView: uiBusy)
    

    This overwrites your rightBarButtonItem with the spinning wheel. When you're done, just recreate the rightBarButtonItem.

提交回复
热议问题