0%

iOS导航栏自定义返回一行代码搞定

iOS导航栏自定义返回一行代码搞定 Custom back button of navigation bar just type a line code in iOS

启用默认的自定义返回按钮 Enable the normal appearance of custom back button

1
2
3
4
5
6
7
- (void)viewDidLoad {
[super viewDidLoad];

// 要启用自定义返回按钮,在基于 EFBaseViewController的控制器
// 的 -viewDidLoad添加这行代码即可
self.useCustomBack = YES;
}

更改自定义返回按钮的外观和行为 Change the appearance and the event handler of custom back button

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
- (void)viewDidLoad {
[super viewDidLoad];

// 你可以在启用前更改自定义返回按钮的外观和行为
self.customBack_barButtonItem = [[UIBarButtonItem alloc] initWithImage:IMAGE(@"extreme.bundle/icon-close-modal") style:UIBarButtonItemStylePlain target:self action:@selector(buttonAction:)];
self.useCustomBack = YES;
// 也可以在启用后更改自定义返回按钮的外观和行为
self.customBack_barButtonItem = nil;
self.customBack_barButtonItem = [[UIBarButtonItem alloc] initWithImage:IMAGE(@"extreme.bundle/icon-close-modal") style:UIBarButtonItemStylePlain target:self action:@selector(buttonAction:)];

// 另一种方式更改自定义返回按钮的行为,同时作用于返回手势
// @WeakObject(self);
// self.customBackHandler = ^(id sender) {
// @StrongObject(self);
// [self performSelector:@selector(buttonAction:) withObject:sender];
// };
}

- (void)buttonAction:(id)sender {
self.useCustomBack = NO;
}

相关