From 184c4f75f9697877c7a8f1d512bef23f557b0c04 Mon Sep 17 00:00:00 2001 From: Matt Holgate Date: Mon, 7 Jul 2014 12:30:25 +0100 Subject: Fix disabled state of bar buttons on iPhone/iPod Touch. Previously on iOS 7, bar buttons didn't change visually when disabled. Also improves the look and feel - the buttons are now tinted in the highlighted state rather than showing a grey background. On iOS 7, the iPhone/iPad buttons style match. Tested on iOS 6 iPad/iPod and iOS 7 iPad/iPod. --- platform/ios/Classes/MuDocumentController.m | 14 +++++++---- platform/ios/Classes/TapImage.h | 9 ------- platform/ios/Classes/TapImage.m | 37 ----------------------------- 3 files changed, 9 insertions(+), 51 deletions(-) delete mode 100644 platform/ios/Classes/TapImage.h delete mode 100644 platform/ios/Classes/TapImage.m (limited to 'platform/ios/Classes') diff --git a/platform/ios/Classes/MuDocumentController.m b/platform/ios/Classes/MuDocumentController.m index c9ac2e66..36f2c867 100644 --- a/platform/ios/Classes/MuDocumentController.m +++ b/platform/ios/Classes/MuDocumentController.m @@ -1,6 +1,5 @@ #include "common.h" -#import #import "MuPageViewNormal.h" #import "MuPageViewReflow.h" #import "MuDocumentController.h" @@ -165,10 +164,15 @@ static void saveDoc(char *current_path, fz_document *doc) } else { - UIView *iv = [[TapImage alloc] initWithResource:resource target:self action:selector]; - UIBarButtonItem *ib = [[UIBarButtonItem alloc] initWithCustomView:iv]; - [iv release]; - return ib; + UIView *buttonView; + BOOL iOS7Style = ([[UIDevice currentDevice].systemVersion floatValue] >= 7.0f); + UIButton *button = [UIButton buttonWithType:iOS7Style ? UIButtonTypeSystem : UIButtonTypeCustom]; + [button setImage:[UIImage imageNamed:resource] forState:UIControlStateNormal]; + [button addTarget:self action:selector forControlEvents:UIControlEventTouchUpInside]; + [button sizeToFit]; + buttonView = button; + + return [[UIBarButtonItem alloc] initWithCustomView:buttonView]; } } diff --git a/platform/ios/Classes/TapImage.h b/platform/ios/Classes/TapImage.h deleted file mode 100644 index af31ea5f..00000000 --- a/platform/ios/Classes/TapImage.h +++ /dev/null @@ -1,9 +0,0 @@ -#import - -@interface TapImage : UIImageView -{ - id target; - SEL action; -} -- (id)initWithResource:(NSString *)resource target:(id)obj action:(SEL)selector; -@end diff --git a/platform/ios/Classes/TapImage.m b/platform/ios/Classes/TapImage.m deleted file mode 100644 index 1a43813e..00000000 --- a/platform/ios/Classes/TapImage.m +++ /dev/null @@ -1,37 +0,0 @@ -#import "TapImage.h" - -static const NSTimeInterval TapDuration = 0.05; - -@implementation TapImage - -- (id)initWithResource:(NSString *)resource target:(id)targ action:(SEL)selector -{ - UIImage *image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:resource ofType:@"png"]]; - if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) - image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; - self = [super initWithImage:image]; - if (self) - { - target = targ; - action = selector; - UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTap)]; - [self addGestureRecognizer:tap]; - [tap release]; - } - return self; -} - -- (void) onTap -{ - [UIView animateWithDuration:TapDuration animations:^{ - self.backgroundColor = [UIColor darkGrayColor]; - } completion:^(BOOL finished) { - [UIView animateWithDuration:TapDuration animations:^{ - self.backgroundColor = [UIColor clearColor]; - } completion:^(BOOL finished) { - [target performSelector:action withObject:nil]; - }]; - }]; -} - -@end -- cgit v1.2.3