Skip to content
This repository has been archived by the owner on Jan 25, 2020. It is now read-only.

Commit

Permalink
Cleaned up toolbar buttons a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
jarush committed Feb 7, 2014
1 parent 2ecf58f commit ddd3f8c
Showing 1 changed file with 35 additions and 42 deletions.
77 changes: 35 additions & 42 deletions MiniKeePass/WebViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ @interface WebViewController () <UIWebViewDelegate, UITextFieldDelegate, MKPWebV
@property (nonatomic, strong) MKPWebView *webView;
@property (nonatomic, strong) UIBarButtonItem *backButton;
@property (nonatomic, strong) UIBarButtonItem *forwardButton;
@property (nonatomic, strong) UIBarButtonItem *reloadStopButton;
@property (nonatomic, strong) UIBarButtonItem *reloadButton;
@property (nonatomic, strong) UIBarButtonItem *stopButton;
@property (nonatomic, strong) UIBarButtonItem *openInButton;
@end

Expand Down Expand Up @@ -118,23 +119,27 @@ - (void)viewDidLoad {
style:UIBarButtonItemStylePlain
target:self
action:@selector(backPressed)];
self.backButton.enabled = NO;

self.forwardButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"forward"]
style:UIBarButtonItemStylePlain
target:self
action:@selector(forwardPressed)];
self.forwardButton.enabled = NO;

self.reloadStopButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
target:self
action:@selector(reloadPressed)];
self.reloadButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
target:self
action:@selector(reloadPressed)];

self.stopButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemStop
target:self
action:@selector(stopPressed)];

self.openInButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction
target:self
action:@selector(openInPressed)];

self.toolbarItems = [self createToolbarItems];
[self updateButtons];

// Load the URL
NSURL *url = [NSURL URLWithString:self.entry.url];
Expand All @@ -159,29 +164,6 @@ - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceO
self.urlTextField.frame = CGRectMake(0, 0, self.navigationController.navigationBar.bounds.size.width, height);
}

- (NSArray *)createToolbarItems {
UIBarButtonItem *fixedSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
target:nil
action:nil];
fixedSpace.width = 10.0f;

UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil
action:nil];

return @[
fixedSpace,
self.backButton,
flexibleSpace,
self.forwardButton,
flexibleSpace,
self.reloadStopButton,
flexibleSpace,
self.openInButton,
fixedSpace
];
}

#pragma mark - URL Text Field

- (void)textFieldEditingDidEnd:(id)sender {
Expand Down Expand Up @@ -236,20 +218,31 @@ - (void)updateButtons {
self.backButton.enabled = self.webView.canGoBack;
self.forwardButton.enabled = self.webView.canGoForward;
self.openInButton.enabled = !self.webView.isLoading;
self.reloadButton.enabled = !self.webView.isLoading;
self.stopButton.enabled = self.webView.isLoading;

if (self.webView.loading) {
self.reloadStopButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemStop
target:self
action:@selector(stopPressed)];
} else {
self.reloadStopButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
target:self
action:@selector(reloadPressed)];
}
UIBarButtonItem *fixedSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
target:nil
action:nil];
fixedSpace.width = 10.0f;

UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil
action:nil];

self.toolbarItems = [self createToolbarItems];
UIBarButtonItem *reloadOrStopButton = self.webView.loading ? self.stopButton : self.reloadButton;

self.toolbarItems = @[
fixedSpace,
self.backButton,
flexibleSpace,
self.forwardButton,
flexibleSpace,
reloadOrStopButton,
flexibleSpace,
self.openInButton,
fixedSpace
];
}

- (void)backPressed {
Expand Down

0 comments on commit ddd3f8c

Please sign in to comment.