From af3476bb0f987479819d5ed11a185c39778df0a8 Mon Sep 17 00:00:00 2001 From: Erik Terwan Date: Thu, 21 Sep 2023 12:04:56 +0200 Subject: [PATCH] Add shadowColor to MMMScrollViewShadowsSettings --- MMMCommonUI.podspec | 2 +- .../MMMCommonUIObjC/MMMScrollViewShadows.h | 3 +++ .../MMMCommonUIObjC/MMMScrollViewShadows.m | 19 +++++++++++++------ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/MMMCommonUI.podspec b/MMMCommonUI.podspec index 42509b4..43afede 100644 --- a/MMMCommonUI.podspec +++ b/MMMCommonUI.podspec @@ -6,7 +6,7 @@ Pod::Spec.new do |s| s.name = "MMMCommonUI" - s.version = "3.8.1" + s.version = "3.9.0" s.summary = "Small UI-related pieces reused in many components from MMMTemple" s.description = "#{s.summary}." s.homepage = "https://github.com/mediamonks/#{s.name}" diff --git a/Sources/MMMCommonUIObjC/MMMScrollViewShadows.h b/Sources/MMMCommonUIObjC/MMMScrollViewShadows.h index fb5b3ac..82786e7 100644 --- a/Sources/MMMCommonUIObjC/MMMScrollViewShadows.h +++ b/Sources/MMMCommonUIObjC/MMMScrollViewShadows.h @@ -41,6 +41,9 @@ NS_ASSUME_NONNULL_BEGIN /** The base shadow color is black with this amount of transparency applied to it. */ @property (nonatomic, readwrite) CGFloat shadowAlpha; +/** The base shadow color, ensure this is an RGB color. Note that the alpha channel is ignored, use ``shadowAlpha`` instead. */ +@property (nonatomic, readwrite) UIColor *shadowColor; + /** * The value between 0 and 1 telling how close to an elliptical curve the shadow's border should be. * diff --git a/Sources/MMMCommonUIObjC/MMMScrollViewShadows.m b/Sources/MMMCommonUIObjC/MMMScrollViewShadows.m index a5ec7cb..6b03383 100644 --- a/Sources/MMMCommonUIObjC/MMMScrollViewShadows.m +++ b/Sources/MMMCommonUIObjC/MMMScrollViewShadows.m @@ -16,7 +16,9 @@ @implementation MMMScrollViewShadowsSettings - (id)init { if (self = [super init]) { - + + _shadowColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0]; + _shadowAlpha = .3; _shadowCurvature = 0.5; @@ -35,7 +37,8 @@ - (id)init { - (id)copyWithZone:(NSZone *)zone { MMMScrollViewShadowsSettings *result = [[MMMScrollViewShadowsSettings alloc] init]; - + + result.shadowColor = self.shadowColor; result.shadowAlpha = self.shadowAlpha; result.shadowCurvature = self.shadowCurvature; @@ -84,16 +87,20 @@ - (void)drawRect:(CGRect)rect { CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); const CGFloat shadowAlpha = _settings.shadowAlpha; - + + CGFloat red, green, blue; + + [_settings.shadowColor getRed:&red green:&green blue:&blue alpha:nil]; + NSInteger numberOfSteps = MAX(8, MIN(b.size.height * 2, 24)); CGFloat *colors = alloca(4 * sizeof(CGFloat) * numberOfSteps); CGFloat *steps = alloca(sizeof(CGFloat) * numberOfSteps); for (NSInteger i = 0; i < numberOfSteps; i++) { CGFloat t = (CGFloat)i / (numberOfSteps - 1); steps[i] = t; - colors[i * 4 + 0] = 0; - colors[i * 4 + 1] = 0; - colors[i * 4 + 2] = 0; + colors[i * 4 + 0] = red; + colors[i * 4 + 1] = green; + colors[i * 4 + 2] = blue; colors[i * 4 + 3] = powf( [MMMAnimation interpolateFrom:shadowAlpha to:0