1

i have UITableView based application, and i can't set backBarButtonItem properly. Back button is button, which appears when i select any item, call second view with method didSelectRowAtIndexPath. When i try to set it like this:

UIButton *back1=[UIButton buttonWithType:UIButtonTypeCustom];
    [back1 setFrame:CGRectMake(10.0, 2.0, 45.0, 40.0)];
    [back1 addTarget:nil action:NULL forControlEvents:UIControlEventTouchUpInside];
    [back1 setImage:[UIImage imageNamed:@"back_button.png"] forState:UIControlStateNormal];
    UIBarButtonItem *back = [[UIBarButtonItem alloc]initWithCustomView:back1];
    self.navigationItem.backBarButtonItem = back;

There is just back button with default style and somehow with title of my TableView controller window.

When i set it like this:

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] 
                               initWithImage:[UIImage imageNamed:@"back_button.png"]
                               style:UIBarButtonItemStyleBordered 
                               target:nil 
                               action:nil];

 self.navigationItem.backBarButtonItem = backButton;

There is an image, but, it look like "inserted" in default back button, doesn't look nice at all.

Please help me.. i tried many ways to solve this, but, in many cases there is just default Back button with title "Products" (there is title which appears on top of navigation bar in my UITableView). Any help would be appreciated!

4

3 に答える 3

2
   UIImage *buttonImage = [UIImage imageNamed:@"back_button.png"];
   UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
   [backButton setBackgroundImage:buttonImage forState:UIControlStateNormal];
  [backButton setTitle:@"Back" forState:UIControlStateNormal];
  backButton.font = [UIFont boldSystemFontOfSize:12];
 backButton.frame = CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height);
 [backButton addTarget:self action:@selector(showMeter) 
       forControlEvents:UIControlEventTouchUpInside];

 self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] 
       initWithCustomView:backButton];
于 2012-07-03T07:28:01.370 に答える
1
//Create resizable images
UIImage *myButton = [[UIImage imageNamed:@"yourButton"] 
        resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 5)];


//Set the background image for *all* UIBackBarButtons
[[UIBarButtonItem appearance] setBackgroundImage:myButton forState:UIControlStateNormal 
    barMetrics:UIBarMetricsDefault];
于 2012-07-04T06:05:48.827 に答える
0

に割り当てる必要がありself.navigationItem.leftBarButtonItemます。

self.navigationItem.leftBarButtonItem = backButton;
于 2012-07-03T07:27:50.993 に答える