Ω我现在已经尝试了一个小时,似乎没有任何效果:
我尝试过的事情:
1)不起作用。
UIImage *image = [UIImage imageNamed:@"scr1_button_topbar.png"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setBackgroundImage: [image stretchableImageWithLeftCapWidth:7.0 topCapHeight:0.0] forState:UIControlStateNormal];
button.frame= CGRectMake(0.0, 0.0, image.size.width, image.size.height);
[button addTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];
UIView *v=[[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, image.size.width, image.size.height) ];
[v addSubview:button];
UIBarButtonItem *forward = [[UIBarButtonItem alloc] initWithCustomView:v];
self.navigationItem.backBarButtonItem= forward;
2)工作,但看起来真的很愚蠢,它留下了“后面”文字。
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:[UIImage imageNamed:@"scr2_btnback"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
3)按钮不显示
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:[UIImage imageNamed:@"scr2_btnback"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
将文字设为@“”
4)设置左栏按钮项目 - Works,但这有点作弊,我想要后退按钮,而不是左按钮。
UIImage *backImage = [UIImage imageNamed:@"scr2_btnback.png"];
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
backButton.frame = CGRectMake(0, 0, backImage.size.width, backImage.size.height);
[backButton setImage:backImage forState:UIControlStateNormal];
[backButton addTarget:self action:@selector(backButton:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton] ;
self.navigationItem.hidesBackButton = YES;
self.navigationItem.leftBarButtonItem = backBarButtonItem;
答案 0 :(得分:0)
刚才被告知,你无法编辑backBarButtonItem的视图......是的。