2013-03-26 140 views

回答

4

我通常使用這種技術,使其工作:

  1. 爲了擺脫默認標題:

    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(-400.f, 0) forBarMetrics:UIBarMetricsDefault]; 
    
  2. 使用可調整大小的圖像:

    UIImage *backButton = [UIImage imageNamed:@"back.png"];   
    [[UIBarButtonItem appearance] setBackButtonBackgroundImage:[backButton resizableImageWithCapInsets:UIEdgeInsetsMake(0, backButton.size.width, 0, 0)] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; 
    
+0

,這確實有用,謝謝你:)和@Jano真的很感謝這個努力! – prabhu 2013-03-26 18:38:32

2

嘗試像

UIButton *back = [UIButton buttonWithType:UIButtonTypeCustom]; 
UIImage *image = ... your image 
[back setBackgroundImage:image forState:UIControlStateNormal]; 
[back addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside]; 
back.frame = CGRectMake(0, 0, image.size.width, image.size.height); 
UIBarButtonItem *backbi = [[UIBarButtonItem alloc] initWithCustomView:back]; 
self.navigationItem.leftBarButtonItem = backbi; 

或發佈您的代碼。

+0

其實我我正在使用這樣的東西 01 UIImage * backButton = [UIImage imageNamed:@「back.png」]; [[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButton forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; – prabhu 2013-03-26 18:16:52

+0

對不起,如果我是一個noob,但self.navigationItem.leftBarButtonItem = backbi; 在AppDelegate類型的對象上未找到屬性'navigationItem' – prabhu 2013-03-26 18:26:32

+1

self.navigationItem只能在從視圖控制器使用時才起作用。 – Jano 2013-03-26 21:15:37