【问题标题】:UITabBarItem selectedImageTintColor. How to find the color to set as tintcolorUITabBarItem selectedImageTintColor。如何找到要设置为 tintcolor 的颜色
【发布时间】:2013-01-21 15:01:23
【问题描述】:

我使用TabBarController 中的selectedImageTintColor 属性来更改所选TabBarItem 的颜色。

问题是您设置为tintcolor 的颜色在更改之前不是最终应用的颜色(它会获得某种渐变)

我的问题是,是否有可能找到应用为tintcolor 的颜色以获得您知道的最终颜色?

例如,我希望我选择的项目的最终颜色为

[UIColor colorWithRed:(154.0/255.0) green:(213.0/255.0) blue:(0.0) alpha:(1.0)

我应该为属性selectedImageTintColor 设置什么颜色的RGB?

【问题讨论】:

标签: ios cocoa-touch uitabbaritem tintcolor


【解决方案1】:

正如 Ankit 已经说过的,你最好的选择是使用

- (void)setFinishedSelectedImage:(UIImage *)selectedImage withFinishedUnselectedImage:(UIImage *)unselectedImage

不过,我很感激您需要一个 UIImage 才能做到这一点。如果你的设计师不能为你提供这个,你可以做的是在代码中绘制你自己的 UIImage。

- (UIImage *)imageWithColor:(UIColor *)color {
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return image;
}

显然,这段代码不会为您绘制渐变,但它向您展示了绘制 UIImage 的基础知识。我会看一下类似下面的教程,以了解如何绘制您想要的确切渐变:

http://www.raywenderlich.com/2033/core-graphics-101-lines-rectangles-and-gradients

【讨论】:

    【解决方案2】:

    iOS 不提供修改 tint 颜色渐变的 api。但是苹果文档建议使用 setFinishedSelectedImage:withFinishedUnSelectedImage: 方法。

    在 UITabBarItem 参考中查看更多信息

    【讨论】:

      猜你喜欢
      • 2019-11-05
      • 1970-01-01
      • 1970-01-01
      • 2012-08-31
      • 1970-01-01
      • 2017-10-21
      • 2021-11-19
      • 2021-07-30
      • 1970-01-01
      相关资源
      最近更新 更多