0

I'm trying to change the navigation controller backBarButton, with out create new function of back. here is my code:

UIImage *backButtonImage = [[UIImage imageNamed:@"backt.clicked@2x~iphone.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 27, 0, 27)];

(width =27,hight=27);

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

and here what i get:

enter image description here

how can i change the size and remove the title?

Joiningss
  • 1,320
  • 9
  • 14
Esti M
  • 193
  • 2
  • 10

2 Answers2

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];
}
shanegao
  • 3,562
  • 1
  • 18
  • 21
Durican Radu
  • 1,327
  • 11
  • 12
  • i want something more simple,i dont want to add new function for the back item,i want to use the default navigation controller back function. – Esti M Nov 27 '13 at 09:04
  • popViewControllerAnimated: this IS the default navigation controller back function :D – Durican Radu Nov 27 '13 at 09:05
  • yeah i know :) but im pretty sure that there is option to change the image only dont u thing? – Esti M Nov 27 '13 at 09:10
  • 1
    That simple option is to change the backGround image of the button, just as you did; but if you want to change the image, and not the backGround image, you should do as I suggested – Durican Radu Nov 27 '13 at 09:13
0

Try this

UIImage *backButtonImage = [[UIImage imageNamed:@"backt.clicked@2x~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];

EDIT

UIImage *backButtonImage = [[UIImage imageNamed:@"backt.clicked@2x~iphone.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 27, 0, 27)];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.topItem.title = @"";
βhargavḯ
  • 9,786
  • 1
  • 37
  • 59
  • i want something more simple,i dont want to add new function for the back item,i want to use the default navigation controller back function. is that possible? – Esti M Nov 27 '13 at 09:05
  • when the title is @"" like u wrote - the back button is disappear.. if i add @" " (with space) its getting to big.. and anyway the image size is not really set.. – Esti M Nov 27 '13 at 09:14
  • @Esty you should really resize your actual image if it is too big. ignore heavy assets – βhargavḯ Nov 27 '13 at 09:16
  • then how can i resize it?? – Esti M Nov 27 '13 at 09:48
  • @Esty you resize image as per navigation size using any image editor :) – βhargavḯ Nov 27 '13 at 09:55