2012-07-26 103 views
0

我使用下面的代码来创建我的工具栏按钮....我想将文本颜色更改为黑色或更好的...设置背景图像为文本着色..... setBackgroundColor不起作用....任何帮助表示赞赏,谢谢。NavBar Toolbar按钮的文字颜色?

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]; 
+1

我在这里回答了这个问题:http://stackoverflow.com/a/6157308/18091 – titaniumdecoy 2012-07-26 17:19:47

+0

我真的想使用背景图片,如果可能的颜色的文字...我没太看在你的链接... thx。 – AhabLives 2012-07-26 17:29:53

回答

0

你可以使用NavigationItem的titleView属性来做你需要做的事情。您可以执行以下操作:

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

而且您应该完成...除非我误解了这个问题。

0

使用此代码可更改工具栏textcolor。

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