注意在Assets.xcassets中添加图片时Appearances 设置为 Any,Dark
@implementation BaseViewController
// 这个方法必须调用super,还有导航里的深色适配必须在这里再适配一遍,类似于设置CGColor
- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
[super traitCollectionDidChange:previousTraitCollection];
UIButton *backBtn = (UIButton *)self.navigationItem.leftBarButtonItem.customView;
if ([backBtn isKindOfClass:[UIButton class]]) {
[backBtn setImage:[[UIImage imageNamed:@"nav_back"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
}
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
backButton.frame = CGRectMake(0, 0, 30, 30);
[backButton setImage:[[UIImage imageNamed:@"nav_back"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
[backButton addTarget:self action:@selector(popAction:) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
}
- (void)popAction:(UIButton *)btn {
[self.navigationController popViewControllerAnimated:YES];
}
@end