- - (void)addBackItemWithAction:(SEL)action {
- if (IOS7_OR_LATER) {
- UIBarButtonItem *returnButtonItem = [[UIBarButtonItem alloc] init];
- returnButtonItem.title = @"返回";
- self.navigationItem.backBarButtonItem = returnButtonItem;
- } else {
- // 设置返回按钮的文本
- UIBarButtonItem *backButton = [[UIBarButtonItem alloc]
- initWithTitle:@"返回"
- style:UIBarButtonItemStylePlain target:nil action:nil];
- [self.navigationItem setBackBarButtonItem:backButton];
- // 设置返回按钮的背景图片
- UIImage *img = [UIImage imageNamed:@"ic_back_nor"];
- img = [img resizableImageWithCapInsets:UIEdgeInsetsMake(0, 18, 0, 0)];
- [[UIBarButtonItem appearance] setBackButtonBackgroundImage:img
- forState:UIControlStateNormal
- barMetrics:UIBarMetricsDefault];
- // 设置文本与图片的偏移量
- [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(5, 0)
- forBarMetrics:UIBarMetricsDefault];
- // 设置文本的属性
- NSDictionary *attributes = @{UITextAttributeFont:[UIFont systemFontOfSize:16],
- UITextAttributeTextShadowOffset:[NSValue valueWithUIOffset:UIOffsetZero]};
- [[UIBarButtonItem appearance] setTitleTextAttributes:attributes forState:UIControlStateNormal];
- }
- return;
- }
-