其他分享
首页 > 其他分享> > 导航条按钮的设置UIBarButtonItem

导航条按钮的设置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 {

}

标签:self,rightNavImage,35,rightNavBtn,UIButton,按钮,导航条,UIBarButtonItem
来源: https://www.cnblogs.com/CH520/p/11485258.html