自定义导航栏左按钮

来源:互联网 发布:淘宝 卖家客服电话 编辑:程序博客网 时间:2024/05/21 08:03

可以用button自定义导航栏左侧按钮,示例代码如下,不过定制后与左侧留有一定宽度,如果想要紧靠左侧,需要重新加个UIView替换原来的NavigationBar,

UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];        button.frame = CGRectMake(0, 0, 50, 40);        [button setBackgroundImage:[UIImage imageNamed:@"nav_menu_icon.png"] forState:UIControlStateNormal];        [button addTarget:self action:@selector(showLeft:) forControlEvents:UIControlEventTouchUpInside];                UIBarButtonItem* barButton = [[UIBarButtonItem alloc] initWithCustomView:button];        topController.navigationItem.leftBarButtonItem = barButton;