IOS 返回事件 UIBarButtonItem (一) 自定义backBarButtonItem

///////  与IOS7 以上滑动返回没有冲突


 UIImage* image = [UIImage imageNamed:imageName];

    UIBarButtonItem *item=[UIBarButtonItem appearance];

    [item setBackButtonBackgroundImage:[image resizableImageWithCapInsets:UIEdgeInsetsMake(0, image.size.width, 0, 0)] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

    [item setBackButtonTitlePositionAdjustment:UIOffsetMake(-400.f, 0) forBarMetrics:UIBarMetricsDefault];

    self.navigationItem.backBarButtonItem = item;








///////  一般返回键

 UIButton *btnb = [UIButton buttonWithType : UIButtonTypeCustom];

    

    

    btnb.frame = CGRectMake (0, 0,  44, 44);

//    [btnb setBackgroundImage :[UIImage imageNamed:imageName] forState:UIControlStateNormal];

    [btnb setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];

    

    if ([UIImage imageNamed:[NSString stringWithFormat:@"%@h",imageName]]) {

         [btnb setImage:[UIImage imageNamed:imageName] forState:UIControlStateHighlighted];

    }

//    btnb.showsTouchWhenHighlighted=YES;

    [btnb addTarget:self action:@selector(showLeft:) forControlEvents:UIControlEventTouchUpInside];

    

    if (ISIOS7LATER) {

        

        btnb.imageEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);

    }

    

    UIBarButtonItem *ubar=[[UIBarButtonItem alloc] initWithCustomView :btnb];

 

    self.navigationItem.backBarButtonItem = ubar;


你可能感兴趣的:(IOS)