导航条按钮的设置UIBarButtonItem

1、目的

2、代码

// 设置导航栏的按钮
UIButton *leftNavBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 35, 35)];
UIImage *leftNavImage = CHImageWithName(@"navBar_schoolTask");
leftNavImage = [leftNavImage imageWithTintColor:[ChanTool appTextColor]];
[leftNavBtn setBackgroundImage:leftNavImage forState:UIControlStateNormal];
[leftNavBtn addTarget:self action:@selector(leftNavClick:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *leftNavButton = [[UIBarButtonItem alloc] initWithCustomView:leftNavBtn];;
self.navigationItem.leftBarButtonItem = leftNavButton;

// 设置导航栏的按钮
UIButton *rightNavBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 35, 35)];
UIImage *rightNavImage = CHImageWithName(@"navBar_takePhoto");
rightNavImage = [rightNavImage imageWithTintColor:[ChanTool appTextColor]];
[rightNavBtn setBackgroundImage:rightNavImage forState:UIControlStateNormal];
[rightNavBtn addTarget:self action:@selector(rightNavClick:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *rightNavButton = [[UIBarButtonItem alloc] initWithCustomView:rightNavBtn];;
self.navigationItem.rightBarButtonItem = rightNavButton;

3、事件

- (void)leftNavClick:(UIButton *)button {


}

- (void)rightNavClick:(UIButton *)button {

}

转载于:https://www.cnblogs.com/CH520/p/11485258.html

你可能感兴趣的:(导航条按钮的设置UIBarButtonItem)