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

}
上一篇:ios中设置UIButton圆角,添加边框


下一篇:Button 连续点击事件