Skip to content

Commit 5448369

Browse files
committed
Support dark theme mode
Replace hardcoded white backgrounds with UIColor.systemBackgroundColor (and secondarySystemBackgroundColor for alternating rows) when available to support Dark Mode. Update cell text colors to use UIColor.labelColor and UIColor.secondaryLabelColor on iOS13+. Avoid forcing navigation bar tint on iOS13. Changes affect AAChartModelListVC, AAOptionsComposerChartListVC, AAOptionsWithJSForChartEventsListVC, MainVC, and OfficialSamplesListVC while preserving legacy colors for older iOS versions.
1 parent 2551bbc commit 5448369

5 files changed

Lines changed: 66 additions & 14 deletions

File tree

AAChartKitDemo/Demo/AAChartListVC/AAChartModelListVC.m

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,11 @@ - (void)viewDidLoad {
156156
],
157157
];
158158

159-
self.view.backgroundColor = [UIColor whiteColor];
159+
if (@available(iOS 13.0, *)) {
160+
self.view.backgroundColor = UIColor.systemBackgroundColor;
161+
} else {
162+
self.view.backgroundColor = [UIColor whiteColor];
163+
}
160164
[self setUpMainTableView];
161165
}
162166

@@ -184,10 +188,20 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
184188
cell.titleLabel.text = textStrArr.firstObject;
185189
cell.subtitleLabel.text = textStrArr.count > 1 ? textStrArr[1] : @"";
186190

187-
if (indexPath.row % 2 == 0) {
188-
cell.backgroundColor = [AAEasyTool colorWithHexString:@"#FFF0F5"];
191+
if (@available(iOS 13.0, *)) {
192+
cell.titleLabel.textColor = UIColor.labelColor;
193+
cell.subtitleLabel.textColor = UIColor.secondaryLabelColor;
194+
if (indexPath.row % 2 == 0) {
195+
cell.backgroundColor = UIColor.systemBackgroundColor;
196+
} else {
197+
cell.backgroundColor = UIColor.secondarySystemBackgroundColor;
198+
}
189199
} else {
190-
cell.backgroundColor = UIColor.whiteColor;
200+
if (indexPath.row % 2 == 0) {
201+
cell.backgroundColor = [AAEasyTool colorWithHexString:@"#FFF0F5"];
202+
} else {
203+
cell.backgroundColor = UIColor.whiteColor;
204+
}
191205
}
192206

193207
return cell;

AAChartKitDemo/Demo/AAChartListVC/AAOptionsComposerChartListVC.m

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSStr
2323
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
2424
if (self) {
2525
self.selectionStyle = UITableViewCellSelectionStyleNone;
26-
self.backgroundColor = UIColor.whiteColor;
26+
if (@available(iOS 13.0, *)) {
27+
self.backgroundColor = UIColor.systemBackgroundColor;
28+
} else {
29+
self.backgroundColor = UIColor.whiteColor;
30+
}
2731

2832
_aaChartView = [[AAChartView alloc] initWithFrame:CGRectZero];
2933
_aaChartView.translatesAutoresizingMaskIntoConstraints = NO;
@@ -58,7 +62,11 @@ - (void)viewDidLoad {
5862
[super viewDidLoad];
5963

6064
self.title = @"AAOptions Composer List";
61-
self.view.backgroundColor = UIColor.whiteColor;
65+
if (@available(iOS 13.0, *)) {
66+
self.view.backgroundColor = UIColor.systemBackgroundColor;
67+
} else {
68+
self.view.backgroundColor = UIColor.whiteColor;
69+
}
6270

6371
self.optionsItems = [AAOptionsComposerProvider aaOptionsComposerItems];
6472
[self setUpTableView];
@@ -70,7 +78,11 @@ - (void)setUpTableView {
7078
self.tableView.delegate = self;
7179
self.tableView.dataSource = self;
7280
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
73-
self.tableView.backgroundColor = UIColor.whiteColor;
81+
if (@available(iOS 13.0, *)) {
82+
self.tableView.backgroundColor = UIColor.systemBackgroundColor;
83+
} else {
84+
self.tableView.backgroundColor = UIColor.whiteColor;
85+
}
7486
[self.tableView registerClass:[AAOptionsComposerChartCell class] forCellReuseIdentifier:kAAOptionsComposerChartCellId];
7587
[self.view addSubview:self.tableView];
7688
}

AAChartKitDemo/Demo/AAChartListVC/AAOptionsWithJSForChartEventsListVC.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,11 @@ - (void)viewDidLoad {
8686
],
8787
];
8888

89-
self.view.backgroundColor = [UIColor whiteColor];
89+
if (@available(iOS 13.0, *)) {
90+
self.view.backgroundColor = UIColor.systemBackgroundColor;
91+
} else {
92+
self.view.backgroundColor = [UIColor whiteColor];
93+
}
9094
[self setUpMainTableView];
9195
}
9296

AAChartKitDemo/Demo/AAChartListVC/MainVC.m

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,21 @@ @implementation MainVC
7070

7171
- (void)viewWillAppear:(BOOL)animated {
7272
[super viewWillAppear:YES];
73-
self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
73+
if (@available(iOS 13.0, *)) {
74+
// Let system handle navigation bar appearance in dark mode
75+
} else {
76+
self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
77+
}
7478
}
7579

7680
- (void)viewDidLoad {
7781
[super viewDidLoad];
7882
self.title = @"AAChartKit";
79-
self.view.backgroundColor = [UIColor whiteColor];
83+
if (@available(iOS 13.0, *)) {
84+
self.view.backgroundColor = UIColor.systemBackgroundColor;
85+
} else {
86+
self.view.backgroundColor = [UIColor whiteColor];
87+
}
8088
_colorsArr = @[
8189
@"#5470c6",
8290
@"#91cc75",
@@ -166,10 +174,20 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
166174
cell.titleLabel.text = textStrArr[0];
167175
cell.subtitleLabel.text = textStrArr[1];
168176

169-
if (indexPath.row % 2 == 0) {
170-
cell.backgroundColor = [AAEasyTool colorWithHexString:@"#FFF0F5"];
177+
if (@available(iOS 13.0, *)) {
178+
cell.titleLabel.textColor = UIColor.labelColor;
179+
cell.subtitleLabel.textColor = UIColor.secondaryLabelColor;
180+
if (indexPath.row % 2 == 0) {
181+
cell.backgroundColor = UIColor.systemBackgroundColor;
182+
} else {
183+
cell.backgroundColor = UIColor.secondarySystemBackgroundColor;
184+
}
171185
} else {
172-
cell.backgroundColor = UIColor.whiteColor;
186+
if (indexPath.row % 2 == 0) {
187+
cell.backgroundColor = [AAEasyTool colorWithHexString:@"#FFF0F5"];
188+
} else {
189+
cell.backgroundColor = UIColor.whiteColor;
190+
}
173191
}
174192

175193
return cell;

AAChartKitDemo/Demo/AAChartListVC/OfficialSamplesListVC.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,11 @@ - (void)viewDidLoad {
8080
],
8181
];
8282

83-
self.view.backgroundColor = UIColor.whiteColor;
83+
if (@available(iOS 13.0, *)) {
84+
self.view.backgroundColor = UIColor.systemBackgroundColor;
85+
} else {
86+
self.view.backgroundColor = UIColor.whiteColor;
87+
}
8488
[self setUpMainTableView];
8589
}
8690

0 commit comments

Comments
 (0)