博客> 百思不得姐笔记
百思不得姐笔记
2017-08-14 06:59 评论:1 阅读:199 vistatinchao
  • (void)initialize //(只执行一次) { // 通过appearance统一设置所有UITabBarItem的文字属性 // 后面带有UI_APPEARANCE_SELECTOR的方法, 都可以通过appearance对象来统一设置 NSMutableDictionary *attrs = [NSMutableDictionary dictionary]; attrs[NSFontAttributeName] = [UIFont systemFontOfSize:12]; attrs[NSForegroundColorAttributeName] = [UIColor grayColor];

    NSMutableDictionary *selectedAttrs = [NSMutableDictionary dictionary]; selectedAttrs[NSFontAttributeName] = attrs[NSFontAttributeName]; selectedAttrs[NSForegroundColorAttributeName] = [UIColor darkGrayColor];

    UITabBarItem *item = [UITabBarItem appearance]; [item setTitleTextAttributes:attrs forState:UIControlStateNormal]; [item setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected]; } /**

    • 可以在这个方法中拦截所有push进来的控制器 */
  • (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 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];

}

pragma mark - 控制器的销毁

  • (void)dealloc { // 停止所有操作 [self.manager.operationQueue cancelAllOperations]; }
收藏
0
sina weixin mail 回到顶部