我总是设置backgroundImages
的UINavigationBars
,但我从来没有计算出如何设置UINavigationBar
的后退按钮的backgroundImage
。自定义UINavigationBar backButton
我该怎么做?
我总是设置backgroundImages
的UINavigationBars
,但我从来没有计算出如何设置UINavigationBar
的后退按钮的backgroundImage
。自定义UINavigationBar backButton
我该怎么做?
我想你将不得不为backBarButtonItem创建一个自定义按钮,然后对其进行自定义。
如果你正在寻找教程,然后去这个问题 - How do you change color/image on the default backBarButtonItem?,我想你在那里找到你的答案。
要使条形按钮项目看起来像backBarButtonItem,请参阅此答案。 Creating a left-arrow button (like UINavigationBar's "back" style) on a UIToolbar
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0,0,36,30);
[button setBackgroundImage:[UIImage imageNamed:@"backgroundImage.png"] forState:UIControlStateNormal];
//[button setTitle:@" Back" forState:UIControlStateNormal];
//[button.titleLabel setFont:[UIFont boldSystemFontOfSize:11]];
[button addTarget:self.navigationController action:@selector(popViewControllerAnimated:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
[self.navigationItem setLeftBarButtonItem:barButtonItem];
UIButton *backbutton = [UIButton buttonWithType:UIButtonTypeCustom];
backbutton.frame = CGRectMake(0,0,36,30);
[backbutton setBackgroundImage:[UIImage imageNamed:@"backgroundImage.png"] forState:UIControlStateNormal];
[backbutton addTarget:self.navigationController action:@selector(popViewControllerAnimated:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backbutton];
[self.navigationItem setLeftBarButtonItem:barButtonItem];
这是一个答案?我不知道我在看什么。 – 2014-02-06 12:51:49
问题是,我想保持它的“箭头”形状,而不是兑换成矩形.. – 2011-06-10 22:41:17
更新的答案。 – Legolas 2011-06-10 22:52:12