1. 程式人生 > >導航欄使用UIButton自定義返回按鈕的圖片

導航欄使用UIButton自定義返回按鈕的圖片

idl smi uic uiimage clas ini anim literal 使用

- (void)viewDidLoad {

UIButton *backItem = [UIButton buttonWithType:UIButtonTypeCustom];

UIBarButtonItem *back = [[UIBarButtonItem alloc] initWithCustomView:backItem];

backItem.frame = CGRectMake(18, 5, 20, 20);

[backItem setImage:[UIImage imageNamed:@"返回 (6)"] forState:UIControlStateNormal];

[backItem addTarget:self action:@selector(backSection1) forControlEvents:UIControlEventTouchUpInside];

self.navigationItem.leftBarButtonItem = back;

}

-(void)backSection1{

if (viewcontrollers.count>1) {

  if ([viewcontrollers objectAtIndex:viewcontrollers.count-1]==self) {   //push方式 [self.navigationController popViewControllerAnimated:YES];
  } } else{ //present方式 [self.navigationController dismissViewControllerAnimated:YES completion:nil]; }


導航欄使用UIButton自定義返回按鈕的圖片