0

On a navigationBar as a rightBarButtonItem I take edit button by the following coding

self.navigationItem.rightBarButtonItem=self.editButtonItem;

but I want to change the color of edit button I mean I want to change the color of rightBarButtonItem. How can I do this?

plz reply as early as possible.

thanx in advance.

iPhone
  • 4,092
  • 3
  • 34
  • 58
  • You can refer my answer for this issue http://stackoverflow.com/questions/7314703/change-uinavigationitem-colour/7315008#7315008 – Nikunj Jadav Sep 14 '11 at 12:46
  • Already solved problem here... http://stackoverflow.com/questions/3274473/how-to-tint-uibarbuttonitem-background-color/6157308#6157308) – alloc_iNit Sep 14 '11 at 12:46

3 Answers3

2

You will need to create a custom button and initialize your UIBarButtonItem using initWithCustomView.

Create your UIButton as you like if with your custom image and then:

UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:yourUIButton];
Bourne
  • 10,094
  • 5
  • 24
  • 51
1

You are constrained making standard UIBarButtonItem. But you can init it with any UIView of your choice, e.g. standard UIButton which you can color as you like.

UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton.frame = CGRectMake(0, 0, 30, 20); // change as you like being constrained with navigation bar hieght
[myButton setTitle:@"My Button" forState:UIControlStateNormal];
[myButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[myButton setImage:[UIImage imageNamed:@"Image for my button.png"] forState:UIControlStateNormal]; // <-- you can provide image instaed of title if you like
[myButton setBackgroundImage:[UIImage imageNamed:@"Background image for my button.png"] forState:UIControlStateNormal];
[myButton addTarget:self action:@selector(myAction) forControlEvents:UIControlEventTouchUpInside]; // <-- don't forget configure this!!! 
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:myButton];
Valeriy Van
  • 1,851
  • 16
  • 19
0

Visit this link. It is kind of same answer.

specially indicating or highlighting a toolbar button when a note is added in iphone

Usage of method [[UIBarButtonItem alloc] initWithCustomView:btnInfo]; can help.

Community
  • 1
  • 1
Mohammad
  • 1,636
  • 1
  • 13
  • 17