AhabLives
AhabLives

Reputation: 1468

NavBar\Toolbar button text color?

I am using the following code to create my toolbar buttons....I would like to change the text color to black or better yet ...set the background image to color the text .....setBackgroundColor would not work....any help is appreciated, Thanks.

UIButton *btnEditLogin = [UIButton buttonWithType:UIButtonTypeCustom];
   [btnEditLogin setBackgroundImage:[UIImage imageNamed:@"btnPlain.png"] forState:UIControlStateNormal];
   [btnEditLogin setTitle:@"Edit Login" forState:UIControlStateNormal];
   [btnEditLogin setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
   btnEditLogin.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:12.0f];
   [btnEditLogin.layer setCornerRadius:5.0f];
   [btnEditLogin.layer setMasksToBounds:YES];
   [btnEditLogin.layer setBorderWidth:1.0f];
   [btnEditLogin.layer setBorderColor: [[UIColor brownColor] CGColor]];
   btnEditLogin.frame=CGRectMake(0.0, 100.0, 90.0, 30.0);
   [btnEditLogin addTarget:self action:@selector(LoginBtn) forControlEvents:UIControlEventTouchUpInside];
   UIBarButtonItem *editLoginItem = [[UIBarButtonItem alloc] initWithCustomView:btnEditLogin];

Upvotes: 0

Views: 413

Answers (2)

neha
neha

Reputation: 167

Use this code to change toolbar textcolor.

UIBarButtonItem *barButtonAppearance = [UIBarButtonItem appearance];
[barButtonAppearance setTintColor:[UIColor redColor]];

Upvotes: 0

Tanvir Ahmed
Tanvir Ahmed

Reputation: 813

You can just use the titleView attribute of NavigationItem to do what you need to do. You can do the following:

UILabel *myLabel = [... enter all the code you want to customize the text, etc here];
self.navigationcontroller.navigationitem.titleView = myLabel;

And you should be done... unless I'm misunderstanding the question.

Upvotes: 0

Related Questions