如何使用barmetrics在iOS中制作没有文本的自定义后退按钮?
问问题
4494 次
3 回答
7
[[UIBarButtonItem appearance]
setBackButtonBackgroundImage:[UIImage imageNamed:@"back_button.png"]
forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
您可以将它放在您的应用程序委托中,它会将背景图像设置为应用程序中的所有后退按钮(当然,对于该控件状态和条形指标)。
编辑: 如果您想要不同的东西,请使用以下代码:
- (void)setBackButton
{
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
[backButton setImage:[UIImage imageNamed:@"BackButton.png"] forState:UIControlStateNormal];
[backButton addTarget:self action:@selector(backButtonTapped:) forControlEvents:UIControlEventTouchUpInside];[button setFrame:CGRectMake(0, 0, 32, 32)];
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:backButton] autorelease];
}
- (void)backButtonTapped:(id)sender
{
[self.navigationController popViewControllerAnimated:YES];
}
于 2013-02-08T18:57:58.580 回答
0
像这样的东西怎么样?
UIButton *backButton = [[UIButton alloc] initWithFrame:CGRectMake(YourFrame)];
[backButton setTitle:@"<" forState:UIControlStateNormal];
[backButton addTarget:self action:@selector(callSelectorMethod) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:backButton] autorelease];
[backButton release],backButton=nil;
于 2013-02-08T18:59:06.607 回答
0
这是解决方案:
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"BackButton.png"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(popBack) forControlEvents:UIControlEventTouchUpInside];
[button setFrame:CGRectMake(0, 0, 32, 32)];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
感谢最佳编码员
于 2013-02-09T03:50:42.343 回答