在使用 UIBarButtonItem  系统提供的几个函数的时发现添加背景图片后会有个小框,而且很难去掉,影响效果,而且UIBarButtonItem好像不能使用frame  的属性,所以可以下面方法定制自己的UIBarButtonItem

  1. UIImage* image= [UIImage imageNamed:@"绑定弹出-返回.png"]; 
  2.         CGRect frame_1= CGRectMake(0, 0, image.size.width, image.size.height-4); 
  3.         UIButton* backButton= [[UIButton alloc] initWithFrame:frame_1]; 
  4.         [backButton setBackgroundImage:image forState:UIControlStateNormal]; 
  5.         [backButton setTitle:@"返回" forState:UIControlStateNormal]; 
  6.         [backButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; 
  7.         backButton.titleLabel.font=[UIFont systemFontOfSize:16]; 
  8.         [backButton addTarget:self action:@selector(doBack:) forControlEvents:UIControlEventTouchUpInside]; 
  9.         
  10. //定制自己的风格的 UIBarButtonItem
  11. UIBarButtonItem* someBarButtonItem= [[UIBarButtonItem alloc] initWithCustomView:backButton]; 
  12.         [self.navigationItem setLeftBarButtonItem:someBarButtonItem]; 
  13.         [someBarButtonItem release]; 
  14.         [backButton release];