Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I used a similar technique to update a button in a UIToolbar when a UIWebView is reloading (as it doesn't appear to be possible to show/hide individual bar button items). In this case, you need to swap out all of the items in the UIToolbar.</p> <pre><code>@property (strong, nonatomic) IBOutlet UIBarButtonItem *refreshBarButton; @property (nonatomic, strong) UIActivityIndicatorView *activityView; @property (nonatomic, strong) UIBarButtonItem *activityBarButton; @property (strong, nonatomic) IBOutlet UIToolbar *toolbar; @property (strong, nonatomic) IBOutlet UIBarButtonItem *backBarButton; @property (strong, nonatomic) IBOutlet UIBarButtonItem *refreshBarButton; @property (strong, nonatomic) IBOutlet UIBarButtonItem *forwardBarButton; </code></pre> <hr> <pre><code>#pragma mark - UIWebViewDelegate -(void)webViewDidFinishLoad:(UIWebView *)webView{ [self updateButtons]; } -(void)webViewDidStartLoad:(UIWebView *)webView{ [self updateButtons]; } -(void)updateButtons{ /* It's not possible to show/hide bar button items so we need to do swap out the toolbar items in order to show the progress view */ //Initialise the activity view if (self.activityBarButton == nil){ self.activityView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)]; self.activityBarButton = [[UIBarButtonItem alloc] initWithCustomView:self.activityView]; self.activityBarButton.enabled = NO; } NSMutableArray *toolbarItems = [[NSMutableArray alloc] initWithArray:self.toolbar.items]; if ([self.webview isLoading]){ //Replace refresh button with loading spinner [toolbarItems replaceObjectAtIndex:[toolbarItems indexOfObject:self.refreshBarButton] withObject:self.activityBarButton]; //Animate the loading spinner [self.activityView startAnimating]; } else{ //Replace loading spinner with refresh button [toolbarItems replaceObjectAtIndex:[toolbarItems indexOfObject:self.activityBarButton] withObject:self.refreshBarButton]; [self.activityView stopAnimating]; } //Set the toolbar items [self.toolbar setItems:toolbarItems]; //Update other buttons self.backBarButton.enabled = [self.webview canGoBack]; self.forwardBarButton.enabled = [self.webview canGoForward]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload