tags:

views:

261

answers:

1

How can I create left or right button in UINavigation controller like backButton?

A: 

As I understand it, it isn't possible to get a button that shape without creating a custom button and specifying the image for it. So basically you would need a button image that's the same shape as the default iphone back button shape.

  UIImage  *backImage = [UIImage imageNamed:@"back_button.png"];

  // Replace the "home" button with a white arrow.
  UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];  
  [backButton addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
  [backButton setFrame:CGRectMake(0.0f, 0, 20, 20)];  

  UIImageView *imageView = [[[UIImageView alloc] initWithImage:backImage] autorelease];
  [imageView setFrame:CGRectMake(0.0f, 0.0f, 20.0f, 20.0f)];
  [backButton addSubview:imageView];

  UIBarButtonItem *homeButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:backButton] autorelease];  
  self.navigationItem.leftBarButtonItem = homeButtonItem;