导航栏左右按钮-文字或图片

导航栏图片

  • 图片处理
    1
    2
    3
    4
    5
    6
    withRenderingMode(.alwaysOriginal)



    ///oc版本
    UIImage *image = [[UIImage imageNamed: @"black_top_more"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

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
func initLetfIterm(){
var img = #imageLiteral(resourceName: "portrait")
img = img.withRenderingMode(.alwaysOriginal)
let item = UIBarButtonItem.init(image:img, style:.plain, target: self, action: #selector(leftLeftBtn(btn:)))
navigationItem.leftBarButtonItem = item
}

@objc func leftLeftBtn(btn: UIButton) {
showLeftMine()
}



func initRightIterm(){
var img = #imageLiteral(resourceName: "date")
img = img?.withRenderingMode(.alwaysOriginal)

let item = UIBarButtonItem.init(image:img, style:.plain, target: self, action: #selector(clickRightbtn(btn:)))
navigationItem.rightBarButtonItem = item
}

@objc func clickRightbtn(btn: UIButton) {
childVC.goActivityVC()
}




UIBarButtonItem *roadLoad = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@""] style:UIBarButtonItemStylePlain target:self action:@selector(roadLoadClicked)];
self.navigationItem.rightBarButtonItem = roadLoad;

- (void)roadLoadClicked{

}

导航栏文字

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
func initRightIterm(){
let item = UIBarButtonItem.init(title: "历史记录", style: .plain, target: self, action: #selector(clickRightbtn(btn:)))
item.tintColor = UIColor.init(hexString: "#4CC6F6")
navigationItem.rightBarButtonItem = item
}

@objc func clickRightbtn(btn: UIButton) {
goChareQuanRecord()
}




UIBarButtonItem *roadLoad = [[UIBarButtonItem alloc] initWithTitle:@"分享" style:UIBarButtonItemStylePlain target:self action:@selector(roadLoadClicked)];
self.navigationItem.rightBarButtonItem = roadLoad;

- (void)roadLoadClicked{

}