如何在导航栏中创建带有图像和标题的后退按钮。下面是我的代码,其中图像和标题都没有在按钮上看到,如何实现这一点。请建议我。
UIButton *nav_BackButton1=[[UIButton alloc] initWithFrame:CGRectMake(5,10 ,60, 24)];
nav_BackButton1.layer.borderColor=[[UIColor blackColor] CGColor];
nav_BackButton1.layer.borderWidth=1.0;
[nav_BackButton1 setTitle:@"Ik" forState:UIControlStateNormal];
[nav_BackButton1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[nav_BackButton1 setTitleEdgeInsets:UIEdgeInsetsMake(0,30, 0, 0)];
[nav_BackButton1 setImage:[UIImage imageNamed:@"ic_action_bar_up.png"] forState:UIControlStateNormal];
[nav_BackButton1 setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 35)];
[nav_BackButton1 addTarget:self action:@selector(backTOChoiceScreen:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *backBarBtn = [[UIBarButtonItem alloc] initWithCustomView:nav_BackButton1];
self.navigationItem.leftBarButtonItem=backBarBtn;
答案 0 :(得分:1)
使用方法setBackgroundImage:forState:
代替setImage:forState:
将背景图片设置为nav_BackButton1
。
答案 1 :(得分:0)
self.navigationItem.leftBarButtonItem = backBarBtn;
使用:
self.navigationItem.hidesBackButton = YES;
self.navigationItem.leftBarButtonItem = backBarBtn;