From f1f30b171baabfedc02fc3c816204a59f7821393 Mon Sep 17 00:00:00 2001 From: Ortwin Gentz Date: Wed, 30 Oct 2024 14:48:51 +0100 Subject: [PATCH] Make use of tint color configurable IASKColorSchemeSystem: color scheme replicating the system settings IASKColorSchemeTinted: color scheme where user-editable options are displayed in tintColor fixes #513 --- InAppSettingsKit.podspec | 2 +- .../Classes/MainViewController.swift | 1 + .../IASKAppSettingsViewController.m | 25 ++++++++++++++++--- .../include/IASKViewController.h | 13 +++++++++- 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/InAppSettingsKit.podspec b/InAppSettingsKit.podspec index 3fb2560f..95377dd5 100644 --- a/InAppSettingsKit.podspec +++ b/InAppSettingsKit.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'InAppSettingsKit' - s.version = '3.8.3' + s.version = '3.8.4' s.summary = 'This iPhone framework allows settings to be in-app in addition to being in the Settings app.' s.description = <<-DESC diff --git a/InAppSettingsKitSampleApp/Classes/MainViewController.swift b/InAppSettingsKitSampleApp/Classes/MainViewController.swift index b115b534..4e1c7324 100644 --- a/InAppSettingsKitSampleApp/Classes/MainViewController.swift +++ b/InAppSettingsKitSampleApp/Classes/MainViewController.swift @@ -38,6 +38,7 @@ class MainViewController: UIViewController { { settingsVC.delegate = self settingsVC.showDoneButton = segue.identifier == "modal" + settingsVC.colorScheme = .tinted settingsViewController = settingsVC } else if let settingsVC = segue.destination as? IASKAppSettingsViewController{ settingsVC.delegate = self diff --git a/Sources/InAppSettingsKit/Controllers/IASKAppSettingsViewController.m b/Sources/InAppSettingsKit/Controllers/IASKAppSettingsViewController.m index 33e48923..c5492810 100644 --- a/Sources/InAppSettingsKit/Controllers/IASKAppSettingsViewController.m +++ b/Sources/InAppSettingsKit/Controllers/IASKAppSettingsViewController.m @@ -66,6 +66,7 @@ @implementation IASKAppSettingsViewController @synthesize childPaneHandler = _childPaneHandler; @synthesize currentFirstResponder = _currentFirstResponder; @synthesize listParentViewController; +@synthesize colorScheme = _colorScheme; #pragma mark accessors - (IASKSettingsReader*)settingsReader { @@ -116,6 +117,18 @@ - (void)setFile:(NSString *)file { } } +- (UIColor*)detailTextColor { + if (self.colorScheme == IASKColorSchemeSystem) { + if (@available(iOS 13.0, *)) { + return UIColor.secondaryLabelColor; + } else { + return [UIColor colorWithRed:0.235294 green:0.235294 blue:0.262745 alpha:0.6]; + } + } else { + return self.tintColor; + } +} + - (void)createSelections { NSMutableArray *sectionSelection = [NSMutableArray new]; for (int section = 0; section < self.settingsReader.numberOfSections; section++) { @@ -649,14 +662,14 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N BOOL hasTitle = title.length > 0 && !specifier.isItemSpecifier; cell.detailTextLabel.text = [[specifier titleForCurrentValue:currentValue ?: specifier.defaultValue] description]; - cell.detailTextLabel.textColor = self.tintColor; + cell.detailTextLabel.textColor = self.detailTextColor; if (hasTitle) { cell.textLabel.text = title; } else { cell.textLabel.text = cell.detailTextLabel.text; cell.detailTextLabel.text = nil; - if (!specifier.parentSpecifier) { + if (!specifier.parentSpecifier && self.colorScheme == IASKColorSchemeTinted) { cell.textLabel.textColor = self.tintColor; } } @@ -698,7 +711,10 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N } cell.userInteractionEnabled = [specifier.type isEqualToString:kIASKDatePickerSpecifier]; if ([specifier.type isEqualToString:kIASKDatePickerSpecifier]) { - cell.detailTextLabel.textColor = [specifier isEqual:self.settingsReader.selectedSpecifier] ? [UILabel appearanceWhenContainedInInstancesOfClasses:@[UITableViewCell.class]].textColor : self.tintColor; + cell.detailTextLabel.textColor = self.detailTextColor; + if ([specifier isEqual:self.settingsReader.selectedSpecifier]) { + cell.detailTextLabel.textColor = [UILabel appearanceWhenContainedInInstancesOfClasses:@[UITableViewCell.class]].textColor; + } } } else if ([specifier.type isEqualToString:kIASKPSTextFieldSpecifier]) { @@ -766,7 +782,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N cell.textLabel.text = [self.settingsReader titleForId:valueString]; } else { cell.detailTextLabel.text = [self.settingsReader titleForId:valueString]; - cell.detailTextLabel.textColor = self.tintColor; + cell.detailTextLabel.textColor = self.detailTextColor; } } } @@ -1061,6 +1077,7 @@ - (void)presentChildViewController:(UITableViewController *) targetViewController.tableView.cellLayoutMarginsFollowReadableWidth = self.cellLayoutMarginsFollowReadableWidth; _currentChildViewController = targetViewController; targetViewController.settingsStore = self.settingsStore; + targetViewController.colorScheme = self.colorScheme; targetViewController.view.tintColor = self.tintColor; if ([specifier.parentSpecifier.type isEqualToString:kIASKListGroupSpecifier]) { NSDictionary *itemDict = @{}; diff --git a/Sources/InAppSettingsKit/include/IASKViewController.h b/Sources/InAppSettingsKit/include/IASKViewController.h index 7cec91cf..fbd5d197 100644 --- a/Sources/InAppSettingsKit/include/IASKViewController.h +++ b/Sources/InAppSettingsKit/include/IASKViewController.h @@ -16,7 +16,15 @@ @class IASKSettingsReader; @protocol IASKSettingsStore; -// protocol all IASK view controllers implement +typedef NS_ENUM(NSUInteger, IASKColorScheme) { + /// color scheme replicating the system settings + IASKColorSchemeSystem = 0, + + /// color scheme where user-editable options are displayed in tintColor + IASKColorSchemeTinted, +}; + +/// protocol all IASK view controllers implement @protocol IASKViewController @property (nonatomic, strong, nullable) IASKSettingsReader* settingsReader; @@ -24,6 +32,9 @@ @property (nonatomic, copy, nullable) void (^childPaneHandler)(BOOL doneEditing); @property (nonatomic, weak, nullable) UIViewController *listParentViewController; +/// defines the use of tintColor, default is `IASKColorSchemeSystem`. +@property (nonatomic) IASKColorScheme colorScheme; + @optional @property (nonatomic, weak, nullable) id currentFirstResponder;