zoukankan      html  css  js  c++  java
  • 风格一致的backItem在项目中怎样设置

    在相应的navigationController中重写- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated方法

    参照代码:

    - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
    {
        if (self.childViewControllers.count > 0) { // 如果push进来的不是第一个控制器
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            [button setTitle:@"返回" forState:UIControlStateNormal];
            [button setImage:[UIImage imageNamed:@"navigationButtonReturn"] forState:UIControlStateNormal];
            [button setImage:[UIImage imageNamed:@"navigationButtonReturnClick"] forState:UIControlStateHighlighted];
            button.size = CGSizeMake(70, 30);
            // 让按钮内部的所有内容左对齐
            button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
            button.backgroundColor = [UIColor redColor];
    //        [button sizeToFit];
            // 让按钮的内容往左边偏移10
            button.contentEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
            [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            [button setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
            [button addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
            
            // 修改导航栏左边的item
            viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
            
            // 隐藏tabbar
            viewController.hidesBottomBarWhenPushed = YES;
        }
        
        // 这句super的push要放在后面, 让viewController可以覆盖上面设置的leftBarButtonItem
        [super pushViewController:viewController animated:animated];
        
    }
  • 相关阅读:
    11.网络请求
    关于 Android 开发中的 127.0.0.1 Connection refused ...
    Android的Handler总结(转)
    httpruner3 运行
    allure安装使用
    初来乍到
    修改 SQL SERVER EXPRESS 登录模式
    关于防止用户表单多次提交方案的思考
    C语言static
    Linux ar 命令的使用说明
  • 原文地址:https://www.cnblogs.com/yintingting/p/4542270.html
Copyright © 2011-2022 走看看