【问题标题】:NavBar\Toolbar button text color?NavBar\Toolbar 按钮文本颜色?
【发布时间】:2016-06-09 17:47:58
【问题描述】:

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

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

【问题讨论】:

  • 我在这里回答了这个问题:stackoverflow.com/a/6157308/18091
  • 如果可能的话,我真的很想使用背景图像来为文本着色...我在您的链接中没有完全看到...谢谢。

标签: objective-c ios uinavigationbar uitoolbar uitoolbaritem


【解决方案1】:

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

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

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

【讨论】:

    【解决方案2】:

    使用此代码更改工具栏文本颜色。

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

    【讨论】:

      猜你喜欢
      • 2014-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-07
      • 2017-04-10
      • 2011-03-14
      • 2021-04-13
      • 1970-01-01
      相关资源
      最近更新 更多