Skip to content

Commit

Permalink
Make use of tint color configurable
Browse files Browse the repository at this point in the history
IASKColorSchemeSystem: color scheme replicating the system settings
IASKColorSchemeTinted: color scheme where user-editable options are displayed in tintColor

fixes #513
  • Loading branch information
futuretap committed Oct 30, 2024
1 parent 8520b49 commit f1f30b1
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
2 changes: 1 addition & 1 deletion InAppSettingsKit.podspec
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions InAppSettingsKitSampleApp/Classes/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ @implementation IASKAppSettingsViewController
@synthesize childPaneHandler = _childPaneHandler;
@synthesize currentFirstResponder = _currentFirstResponder;
@synthesize listParentViewController;
@synthesize colorScheme = _colorScheme;

#pragma mark accessors
- (IASKSettingsReader*)settingsReader {
Expand Down Expand Up @@ -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++) {
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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]) {
Expand Down Expand Up @@ -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;
}
}
}
Expand Down Expand Up @@ -1061,6 +1077,7 @@ - (void)presentChildViewController:(UITableViewController<IASKViewController> *)
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 = @{};
Expand Down
13 changes: 12 additions & 1 deletion Sources/InAppSettingsKit/include/IASKViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,25 @@
@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 <NSObject>

@property (nonatomic, strong, nullable) IASKSettingsReader* settingsReader;
@property (nonatomic, strong, nonnull) id<IASKSettingsStore> settingsStore;
@property (nonatomic, copy, nullable) void (^childPaneHandler)(BOOL doneEditing);
@property (nonatomic, weak, nullable) UIViewController<IASKViewController> *listParentViewController;

/// defines the use of tintColor, default is `IASKColorSchemeSystem`.
@property (nonatomic) IASKColorScheme colorScheme;

@optional
@property (nonatomic, weak, nullable) id currentFirstResponder;

Expand Down

0 comments on commit f1f30b1

Please sign in to comment.