2013-11-27 183 views
0

我試圖改變導航控制器backBarButton, 與出後創建新功能。 這裏是我的代碼:更改UIBarButtonItem後退按鈕

UIImage *backButtonImage = [[UIImage imageNamed:@"[email protected]~iphone.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 27, 0, 27)]; 

(寬度= 27,HIGHT = 27);

[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; 

,在這裏我得到什麼:

enter image description here

我怎樣才能改變大小和去掉標題?

+0

RESD這http://stackoverflow.com/questions/1449339/how-do-i-change-the-title -of-back-button-on-a-navigation-bar –

+0

thanx但它不工作以太... –

+0

你試過的代碼是什麼,在這裏粘貼你的代碼。 –

回答

0
- (UIBarButtonItem *)createBackMenuButton { 
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
    [backButton addTarget:self action:@selector(popViewControllerAnimated:) forControlEvents:UIControlEventTouchUpInside]; 
    [backButton setFrame:BACK_BUTTON_FRAME]; 
    [backButton setExclusiveTouch:YES]; 
    [backButton setImage:[UIImage imageNamed:BACK_BUTTON_DEFAULT_ICON] forState:UIControlStateNormal]; 

    UIBarButtonItem *backButtonHolder = [[UIBarButtonItem alloc] initWithCustomView:backButton]; 
    return backButtonHolder; 
} 

- (void)viewWillAppear:(BOOL)animated { 

    self.navigationItem.leftBarButtonItem = [self createBackMenuButton]; 
} 
+0

我想要更簡單的東西,我不想爲後面的項目添加新的功能,我想使用默認的導航控制器後退功能。 –

+0

popViewControllerAnimated:這是默認的導航控制器返回功能:D –

+0

是的,我知道:) 但我敢肯定,有選擇更改圖像只有你不是嗎? –

0

試試這個

UIImage *backButtonImage = [[UIImage imageNamed:@"[email protected]~iphone.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 27, 0, 27)]; 
CGRect frame = CGRectMake(0, 0, backButtonImage.size.width, backButtonImage.size.height); 

UIButton *button = [[UIButton alloc] initWithFrame:frame]; 
[button setImage:backButtonImage forState:UIControlStateNormal]; 
[button addTarget:self action:@selector(backButtonPressed:) forControlEvents:UIControlEventTouchUpInside]; 

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button]; 

編輯

UIImage *backButtonImage = [[UIImage imageNamed:@"[email protected]~iphone.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 27, 0, 27)]; 
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; 
self.navigationController.navigationBar.topItem.title = @""; 
+0

我想要一些更簡單的東西,我不想爲後面的項目添加新的功能,我想使用默認的導航控制器後退功能。 是可能的嗎? –

+0

@Esty檢查更新的答案。 –

+0

當標題是@「」像你寫的 - 後退按鈕是消失.. 如果我加@「」(與空間)其得到大.. 和反正圖像大小是不是真的設置.. –

相關問題