【问题标题】:Change tint color of tabbar edit view controller更改标签栏编辑视图控制器的色调颜色
【发布时间】:2015-03-25 06:13:03
【问题描述】:

我想更改标签栏控制器的编辑视图控制器的色调颜色。我已经设法更改了更多视图控制器的颜色,但没有得到任何线索。

这段代码是为了改变更多视图控制器的颜色,写在UITabBarController的子类中

  override func viewDidLoad() {
    super.viewDidLoad()
    var view = self.moreNavigationController.topViewController.view as UITableView
    view.tintColor = Utilities.mainColor()
    view.separatorStyle = .None
  }

欢迎对 Objective-C 或 Swift 提出建议

【问题讨论】:

  • 设置全局色调颜色最简单的方法是设置 AppDelegate.window.tintColor。
  • 尝试使用这个self.moreNavigationController.view.tintColor = Utilities.mainColor();而不是在topViewController上应用色调
  • @Zahid 它不起作用,它只是改变了 MoreViewController 的色调而不是编辑 vc

标签: ios objective-c iphone swift


【解决方案1】:

通过尝试下面的代码为我工作

  override func viewDidLoad() {
    super.viewDidLoad()
    //this line helped me
    self.view.tintColor = Utilities.mainColor()
  }

【讨论】:

    【解决方案2】:

    您可以为tabBarItem 手动设置彩色图像。

    UIImage *defaultImage = [UIImage imageNamed:@"sports"];
    defaultImage = [defaultImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];//system tints wont apply on the default image
    UIImage *selectedImage = [[UIImage imageNamed:@"sports"] imageWithColor:tintColor];
    selectedImage = [selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];//System tints wont apply on this image
    UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:@"Sports" image:defaultImage selectedImage:selectedImage];
            }
    

    以下功能可用于手动着色图像

    - (UIImage *)imageWithColor:(UIColor *)color1
    {
        UIGraphicsBeginImageContextWithOptions(self.size, NO, self.scale);
        CGContextRef context = UIGraphicsGetCurrentContext();
        CGContextTranslateCTM(context, 0, self.size.height);
        CGContextScaleCTM(context, 1.0, -1.0);
        CGContextSetBlendMode(context, kCGBlendModeNormal);
        CGRect rect = CGRectMake(0, 0, self.size.width, self.size.height);
        CGContextClipToMask(context, rect, self.CGImage);
        [color1 setFill];
        CGContextFillRect(context, rect);
        UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return newImage;
    }
    

    【讨论】:

      猜你喜欢
      • 2017-08-23
      • 1970-01-01
      • 2015-07-11
      • 2016-01-14
      • 2013-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-18
      相关资源
      最近更新 更多