单军华
2017-07-12 20d1260d26b028897f3c0935c12fc35aa37b2e93
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//
//  BaseNavPage.m
//  airtree
//
//  Created by WindShan on 2016/11/15.
//  Copyright © 2016年 Gloria. All rights reserved.
//
 
#import "BaseNavPage.h"
 
@interface BaseNavPage ()
 
@end
 
@implementation BaseNavPage
 
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.barBackgroudImage = @"NavigationBar";
    [super viewDidLoad];
}
 
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    [self setNavigationBackground];
}
 
- (void)setNavigationBackground
{
    NSString *imageName = [self.barBackgroudImage stringByAppendingFormat:@"%d.png", [Global isSystemLowIOS7]?NavBarHeight:NavBarHeight7];
    UIImage *image = [UIImage imageNamed:imageName];
    [self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    
    NSDictionary *attribute = @{
                                NSForegroundColorAttributeName:[UIColor whiteColor],
                                NSFontAttributeName:[UIFont systemFontOfSize:18]
                                };
    
    [self.navigationController.navigationBar setTitleTextAttributes:attribute];
}
 
 
 
- (UIButton *)customButton:(NSString *)title
                  selector:(SEL)sel
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    if ([title hasSuffix:@"png"]) {
        [btn setImage:[UIImage imageNamed:title] forState:UIControlStateNormal];
    }
    else {
        [btn setTitle:title forState:UIControlStateNormal];
    }
    
    btn.frame = CGRectMake(0, 0, 44, 44);
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btn addTarget:self action:sel forControlEvents:UIControlEventTouchUpInside];
    
    return btn;
}
 
- (void)setNavigationItem:(NSString *)title  color:(UIColor*)color selector:(SEL)selector isRight:(BOOL)isRight
{
    UIBarButtonItem *item = nil;
    
    if ([Global isSystemLowIOS7])
    {
        UIButton *btn = [self customButton:title selector:selector];
        item = [[UIBarButtonItem alloc] initWithCustomView:btn];
    }
    else
    {
        if ([title hasSuffix:@"png"])
        {
            item = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:title] style:UIBarButtonItemStylePlain target:self action:selector];
        }
        else
        {
            item = [[UIBarButtonItem alloc] initWithTitle:title style:UIBarButtonItemStylePlain target:self action:selector];
        }
        
        item.tintColor = color;
    }
    
    if (isRight)
        self.navigationItem.rightBarButtonItem = item;
    else
        self.navigationItem.leftBarButtonItem = item;
}
/*
#pragma mark - Navigation
 
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
 
@end