【问题标题】:back button don't get change color in navigation bar后退按钮不会在导航栏中更改颜色
【发布时间】:2014-02-08 04:32:58
【问题描述】:

抱歉英语不好:-(
这里我使用的是 xcode 5 和 ios7,在 pushviewcontroller 之后无法更改后退按钮的颜色。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        ListViewController *viewList = [[ListViewController alloc] initWithNibName:@“ListViewController” bundle:nil];
        [self.navigationController pushViewController: viewList animated:YES];
}

用户按下一个单元格然后 ListViewController 将出现。在导航栏中,右栏按钮出现粉红色。但没有在后栏按钮中更改颜色。请看我在下面附上链接的屏幕截图。

我们可以更改导航栏中返回按钮的颜色吗?还是应该在后退按钮中添加图片?

【问题讨论】:

  • 这个颜色是ios7默认颜色,你应该只用图片替换它。

标签: ios iphone xcode uinavigationcontroller


【解决方案1】:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        ListViewController *viewList = [[ListViewController alloc] initWithNibName:@“ListViewController” bundle:nil];
        self.navigationController.navigationBar.tintColor=[UIColor readcolor]; //set color as you want…..
        [self.navigationController pushViewController: viewList animated:YES];
}

试试吧...快乐的代码:-)

【讨论】:

    【解决方案2】:

    要更改应用程序中的所有 UIBarButtonItems 颜色,请在 AppDelegate 中的应用程序窗口上设置 tintColor 属性。比如,

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window.tintColor = [UIColor blueColor]; // or set color as you want.
        return YES;
    }
    

    【讨论】:

    • 也可以在情节提要中设置。
    【解决方案3】:

    您无法更改backBarButtonItem 的颜色,但可以更改其色调。尝试将以下内容添加到您的 App Delegate 中: [[UIBarButtonItem appearance] setTintColour:pinkColour]

    小心,这会将您的所有条形按钮染成粉红色。

    【讨论】:

      【解决方案4】:

      试试这个自定义后退按钮

      UIView *backBtnView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 70, 40)];
      backBtnView.backgroundColor = [UIColor clearColor];
      UIButton *backBtn=[UIButton buttonWithType:UIButtonTypeCustom];
      [backBtn setBackgroundColor:[UIColor clearColor]];
      [backBtn setImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];
      [backBtn addTarget:self action:@selector(backBtnClicked) forControlEvents:UIControlEventTouchUpInside];
      [backBtn setFrame:CGRectMake(5, 5, 57, 30)];
      [backBtnView addSubview:backBtn];
      self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]initWithCustomView:backBtnView];
      

      【讨论】:

        猜你喜欢
        • 2015-04-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-11-16
        • 1970-01-01
        • 2011-12-17
        • 2015-07-01
        相关资源
        最近更新 更多