我總是設置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