Question

I would like to create an algorithm for computing highlight tint color from a given tint color for my custom UI controls.

By highlight tint color I mean the color which is shown in standard iOS UI controls like UISegmentedView when highligting items. See here:

enter image description here

Is there an official information regarding the way how this color is computed? Are there any open source libraries (e.g. for custom components) which would compute the color? Or is there an UIColor category which would do exactly what I want to achieve?

Was it helpful?

Solution

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. I've created a simple category which creates this color from the tint color.

UIColor+HighlightTintColor.h

@interface UIColor (HighlightTintColor)

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

@end

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top