0

In my detail view controller (part of navigation controller application) I've added custom "Back" button, like this:

- (void)loadView
{
    [super loadView];

    UIButton *backButton = [[UIButton alloc] initWithFrame: CGRectMake(0, 0, 10.0f, 24.0f)];

    UIImage *backImage = [UIImage imageNamed:@"left_arrow_icon"];
    [backButton setBackgroundImage:backImage  forState:UIControlStateNormal];

    [backButton setTitle:@"" forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(popBack) forControlEvents:UIControlEventTouchUpInside];

    UIBarButtonItem *backButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];

    self.navigationItem.leftBarButtonItem = backButtonItem;
}

-(void) popBack {
    [self.navigationController popViewControllerAnimated:YES];
}

As you can see I added left bar button and assign "popBack" action. Basically left_arrow_icon is silver but when I press it, iOS change it darker grey.

My question is, can I (and how) change initial colour to white? Is that possible?

Edit. I use xcode5

Edit2: That does't work too enter image description here

Marshall
  • 1,195
  • 6
  • 30
  • 47
  • http://stackoverflow.com/questions/11583603/iphone-set-tint-color-of-back-bar-button-item – user241641 Nov 22 '13 at 08:45
  • This solution changes only icons that I've added via storyboard. But this one icon I add in code, and it doesn't change. It stays silver.. – Marshall Nov 22 '13 at 09:57

2 Answers2

0

Try this code -

[backbutton setTitleTextAttributes: 
    [NSDictionary dictionaryWithObjectsAndKeys:[UIColor blackColor], UITextAttributeTextColor,
    [UIColor blackColor], UITextAttributeTextShadowColor, 
    [NSValue valueWithUIOffset:UIOffsetMake(0, -1)], UITextAttributeTextShadowOffset, 
    [UIFont fontWithName:HELVETICA_REGULAR_FONT size:17.0], UITextAttributeFont, nil] forState:UIControlStateNormal];
IluTov
  • 6,807
  • 6
  • 41
  • 103
  • you tried this right?? [.... NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], UITextAttributeTextColor,......] – Aravind Bhuvanendran Nov 22 '13 at 14:10
  • Well, u wrote backbutton (which is in my example UIButton). UIButton does not have setTitleTextAttributes method. So I assume, u meant backButtonItem. So I did (loot at my edit2 in question).. and it didn't work – Marshall Nov 22 '13 at 23:40
0

Try this code. It works perfectly for me -

UIImageView *navigationBarImage = [[UIImageView alloc] initWithImage:[UIImage    imageNamed:@"Navigation.png"]];
navigationBarImage.frame = CGRectMake(0, 0, 320, 44);
navigationBarImage.userInteractionEnabled = YES;
navigationBarImage.backgroundColor = [UIColor colorWithRed:28.0/255.0 green:53.0/255.0 blue:102.0/255.0 alpha:1.0];
[self.view navigationBarImage];
[navigationBarImage release];

UIButton *backBarBtn1 = [UIButton buttonWithType:UIButtonTypeCustom];
backBarBtn1.frame = CGRectMake(13, 12, 20, 20);
[backBarBtn1 setImage:[UIImage imageNamed:@"ic_back3.png"] forState:UIControlStateNormal];
backBarBtn1.backgroundColor = [UIColor clearColor];
[backBarBtn1 addTarget:self action:@selector(backBtnAction:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:backBarBtn1];
iSmita
  • 1,292
  • 1
  • 9
  • 24
  • Why do u declare UIImageView? Could you paste your loadView method? – Marshall Nov 22 '13 at 10:23
  • Actually, Here I want to create custom navigationBar, and that image view is for navigationBar image. – iSmita Nov 22 '13 at 10:27
  • I need to add only button to navigation bar. I want to have my own png icon in the left top corner. The arrow in png file is silver. And using the code I shown above, I can see my arrow, action to "go back" works also… but I would like to have this icon pure white. There must be a way, because Xcode or "sth" change this light silver colour to dark grey (when button is pressed) :/ – Marshall Nov 22 '13 at 11:49