自定义navigationbar左边的按钮

先放这里,以后复制就好~
viewdidload:
self.navigationItem.leftBarButtonItem = [self leftBarButtonItem];
其它函数:
- (UIBarButtonItem *)leftBarButtonItem{
  
    UIButton *left = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 11, 20)];
    [left setBackgroundImage:[UIImage imageNamed:@"nav_back"] forState:UIControlStateNormal];
    [left addTarget:self action:@selector(popViewCon) forControlEvents:UIControlEventTouchUpInside];
    [left setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [left setTitleColor:[UIColor blueColor] forState:UIControlStateHighlighted];
  
    UIBarButtonItem *item = [self barItemWithCustomView:left];
    return item;
}
- (UIBarButtonItem *)barItemWithCustomView:(id)custom{
    return [[UIBarButtonItem alloc]initWithCustomView:(UIView *)custom];
}
-(void)popViewCon
{
    [self.navigationController popViewControllerAnimated:YES];
}

评论

此博客中的热门博文

使__attribute__((annotate("xxx")))能作用于OC函数

viewWillAppear不执行的解决办法

iOS中使用xpc/xpc.h