blob: da20f374e9eeaa74f07f83946942637d8caeb78d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
#import "Common.h"
#import "UIViewController+Navigation.h"
namespace
{
CGFloat constexpr kButtonExtraWidth = 16.0;
} // namespace
@implementation UIViewController (Navigation)
- (UIBarButtonItem *)negativeSpacer
{
UIBarButtonItem * spacer =
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
target:nil
action:nil];
spacer.width = -kButtonExtraWidth;
return spacer;
}
- (UIBarButtonItem *)buttonWithImage:(UIImage *)image action:(SEL)action
{
CGSize const buttonSize = {image.size.width + kButtonExtraWidth, image.size.height};
UIButton * button = [[UIButton alloc] initWithFrame:{{}, buttonSize}];
[button setImage:image forState:UIControlStateNormal];
[button addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
return [[UIBarButtonItem alloc] initWithCustomView:button];
}
- (NSArray<UIBarButtonItem *> *)alignedNavBarButtonItems:(NSArray<UIBarButtonItem *> *)items
{
return [@[ [self negativeSpacer] ] arrayByAddingObjectsFromArray:items];
}
- (UIBarButtonItem *)backButton
{
return [self buttonWithImage:[UIImage imageNamed:@"ic_nav_bar_back"] action:@selector(backTap)];
}
- (void)showBackButton
{
self.navigationItem.leftBarButtonItems = [self alignedNavBarButtonItems:@[ [self backButton] ]];
}
- (void)backTap { [self.navigationController popViewControllerAnimated:YES]; }
- (UIStoryboard *)mainStoryboard { return [UIStoryboard storyboardWithName:@"Mapsme" bundle:nil]; }
@end
|