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

2021-08-24  本文已影响0人  fredericoyang

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

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

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

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

- (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;
}

相关

许可

查看原文

上一篇 下一篇

猜你喜欢

热点阅读