Skip to content

Commit 5d46c6b

Browse files
committed
Lowered the saturation boost of the dynamically generated tap color
1 parent 8f9b703 commit 5d46c6b

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

TORoundedButton/TORoundedButton.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,10 @@ IB_DESIGNABLE @interface TORoundedButton : UIControl
117117
/// (Defaults to off with 1.0f).
118118
@property (nonatomic, assign) IBInspectable CGFloat tappedTextAlpha;
119119

120-
/// Taking the default button background color apply a brightness offset for the tapped color
120+
/// The color of the button's rounded background shape. Applied to `.solid` and `.glass` styles.
121+
@property (nonatomic, strong, nullable) UIColor *tintColor;
122+
123+
/// Taking the default button background color apply a brightness offset for the tapped color
121124
/// (Default is 0.25f. Set 0.0 for off).
122125
@property (nonatomic, assign) IBInspectable CGFloat tappedTintColorBrightnessOffset;
123126

TORoundedButton/TORoundedButton.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,14 @@ - (UIColor *)_brightnessAdjustedColorWithColor:(UIColor *)color amount:(CGFloat)
734734
brightnessAdd = 0.18f * amount;
735735
}
736736

737+
// Greys and other near-neutral colours carry a meaningless hue plus a faint
738+
// undertone (e.g. systemGray leans slightly blue). Boosting their saturation
739+
// amplifies that undertone into a visible tint, so scale the hue/saturation
740+
// changes by how saturated the source already is — leaving brightness alone.
741+
const CGFloat colorfulness = fminf(s / 0.15f, 1.0f);
742+
hueShift *= colorfulness;
743+
satBoost *= colorfulness;
744+
737745
// Apply hue shift with wrapping
738746
CGFloat newH = h + hueShift;
739747
if (newH < 0.0f) { newH += 1.0f; }

0 commit comments

Comments
 (0)