首页 > 代码库 > 自定义导航栏按钮 baseViewController中写!
自定义导航栏按钮 baseViewController中写!
// 自定义导航栏"返回按钮"
- (void)initNaviBackBtn
{
UIButton *backBtn = [UIButtonbuttonWithType:UIButtonTypeCustom];
backBtn.frame = CGRectMake(0, 0, 50, 22);
[backBtn setImage:[UIImageimageNamed:@"backBtn"] forState:UIControlStateNormal];
[backBtn addTarget:selfaction:@selector(back) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *backItem = [[UIBarButtonItemalloc] initWithCustomView:backBtn];
// 控制按钮的左右间距
UIBarButtonItem *negativeSpacer = [[UIBarButtonItemalloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
target:nilaction:nil];
if (IOS_VERSION_6) {
negativeSpacer.width = 2;
} else {
negativeSpacer.width = -9;
}
self.navigationItem.leftBarButtonItems = [NSArrayarrayWithObjects:negativeSpacer, backItem, nil];
// self.navigationItem.leftBarButtonItem = backItem;
}
自定义导航栏按钮 baseViewController中写!