Navigation bar button item image color is different when design through xib of xcode5

前端 未结 6 595
自闭症患者
自闭症患者 2021-02-03 20:46

I am creating navigation bar button using xib but when i going to set image to bar button then image colour is different as original image.

Here is my orignal image.

6条回答
  •  暖寄归人
    2021-02-03 21:49

    You can create navigation bar button programmatically instead of direct storyboard, this will not affect original image color

    self.navigationItem.leftBarButtonItem=[self backButton];
    
    - (UIBarButtonItem *)backButton
    {
       UIImage *image = [UIImage imageNamed:@"image.png"];
       CGRect buttonFrame = CGRectMake(0, 0, image.size.width, image.size.height);
    
       UIButton *button = [[UIButton alloc] initWithFrame:buttonFrame];
       //[button addTarget:self action:@selector(backButtonPressed) forControlEvents:UIControlEventTouchUpInside];
       [button setImage:image forState:UIControlStateNormal];
    
       UIBarButtonItem *item= [[UIBarButtonItem alloc] initWithCustomView:button];
    
       return item;
    }
    

提交回复
热议问题