简体   繁体   English

在iOS 7中,例如在UISegmentedView中计算突出显示色调颜色

[英]Computing Highlight Tint Color in iOS 7 e.g. in UISegmentedView

I would like to create an algorithm for computing highlight tint color from a given tint color for my custom UI controls. 我想为自定义UI控件创建一种算法,该算法可以根据给定的色彩来计算高光色彩。

By highlight tint color I mean the color which is shown in standard iOS UI controls like UISegmentedView when highligting items. 高亮色是指在对项目进行高亮显示时,在标准iOS UI控件(如UISegmentedView)中显示的颜色。 See here: 看这里:

在此处输入图片说明

Is there an official information regarding the way how this color is computed? 是否有关于此颜色的计算方式的官方信息? Are there any open source libraries (eg for custom components) which would compute the color? 是否有任何用于计算颜色的开源库(例如,用于自定义组件)? Or is there an UIColor category which would do exactly what I want to achieve? 还是有UIColor类别可以完全实现我想要实现的目标?

As Desdenova mentioned in a comment, it really seems like the highlight tint color is the same color as the tint color with 15% opacity. 正如Desdenova在评论中提到的那样,看起来高亮色调颜色确实与不透明度为15%的色调颜色相同。 I've created a simple category which creates this color from the tint color. 我创建了一个简单的类别,该类别从色调颜色创建了该颜色。

UIColor+HighlightTintColor.h UIColor + HighlightTintColor.h

@interface UIColor (HighlightTintColor)

- (instancetype)highlightTintColor;
+ (instancetype)highlightTintColorForTintColor:(UIColor *)tintColor;

@end

UIColor+HighlightTintColor.m UIColor + HighlightTintColor.m

#import "UIColor+HighlightTintColor.h"

@implementation UIColor (HighlightTintColor)

- (instancetype)highlightTintColor
{
    return [[self class] highlightTintColorForTintColor:self];
}

+ (instancetype)highlightTintColorForTintColor:(UIColor *)tintColor
{
    return [tintColor colorWithAlphaComponent:0.15];
}

@end

If there are better suggestions, please post your answers and if they are better than this one, I will accept them. 如果有更好的建议,请发表您的答案,如果比这个要好,我会接受的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM