Skip to content

Commit

Permalink
Merge pull request #67 from vtourraine/dark-mode-colors
Browse files Browse the repository at this point in the history
Improve Dark Mode support
  • Loading branch information
vtourraine committed Apr 13, 2020
2 parents 54a6687 + 951663e commit 857ad1e
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 78 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ language: objective-c
xcode_workspace: Tests/VTAck Tests.xcworkspace
xcode_scheme: VTAck Tests
xcode_sdk: iphonesimulator
osx_image: xcode9
osx_image: xcode11

script:
- xcodebuild test -workspace "Tests/VTAck Tests.xcworkspace" -scheme "VTAck Tests" -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 7,OS=11.0' ONLY_ACTIVE_ARCH=NO
- xcodebuild test -workspace "Tests/VTAck Tests.xcworkspace" -scheme "VTAck Tests" -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 8,OS=13.0' ONLY_ACTIVE_ARCH=NO
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 1.5.2 (work in progress)

- Improve Dark Mode support


## 1.5.1 (4 December 2018)

- Improve Dynamic Type support, by @kiancheong
Expand Down
1 change: 0 additions & 1 deletion Classes/VTAcknowledgementViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ - (void)viewDidLoad {
textView.panGestureRecognizer.allowedTouchTypes = @[@(UITouchTypeIndirect)];
#endif
textView.textContainerInset = UIEdgeInsetsMake(VTTopBottomDefaultMargin, VTLeftRightDefaultMargin, VTTopBottomDefaultMargin, VTLeftRightDefaultMargin);
self.view.backgroundColor = [UIColor whiteColor];
[self.view addSubview:textView];

self.textView = textView;
Expand Down
137 changes: 62 additions & 75 deletions Classes/VTAcknowledgementsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -182,63 +182,93 @@ - (void)viewDidLoad {
#endif
}

- (UIFont *)headerFooterFont {
if ([UIFont respondsToSelector:@selector(preferredFontForTextStyle:)]) {
return [UIFont preferredFontForTextStyle:UIFontTextStyleFootnote];
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];

if (self.presentingViewController && self == [self.navigationController.viewControllers firstObject]) {
UIBarButtonItem *doneItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismissViewController:)];
#if !TARGET_OS_TV
self.navigationItem.leftBarButtonItem = doneItem;
#else
// Add a spacer item because the leftBarButtonItem is misplaced on tvOS (doesn't obey the HIG)
UIBarButtonItem *spacerItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
spacerItem.width = 90.0;
self.navigationItem.leftBarButtonItems = @[spacerItem, doneItem];
#endif
}
else {
return [UIFont systemFontOfSize:12];

[self.tableView deselectRowAtIndexPath:self.tableView.indexPathForSelectedRow animated:animated];
}

- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];

if (self.acknowledgements.count == 0) {
NSLog(@"** VTAcknowledgementsViewController Warning **");
NSLog(@"No acknowledgements found.");
NSLog(@"This probably means that you didn’t import the `Pods-acknowledgements.plist` to your main target.");
NSLog(@"Please take a look at https://github.com/vtourraine/VTAcknowledgementsViewController for instructions.");
}
}

- (void)configureHeaderView {
UIFont *font = [self headerFooterFont];
CGFloat labelWidth = CGRectGetWidth(self.view.frame) - 2 * VTLabelMargin;
CGFloat labelHeight = [self heightForLabelWithText:self.headerText andWidth:labelWidth];
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];

[coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
if (self.headerText) {
[self configureHeaderView];
}

if (self.footerText) {
[self configureFooterView];
}
}];
}

CGRect labelFrame = CGRectMake(VTLabelMargin, VTLabelMargin, labelWidth, labelHeight);
- (UIFont *)headerFooterFont {
return [UIFont preferredFontForTextStyle:UIFontTextStyleFootnote];
}

UILabel *label = [[UILabel alloc] initWithFrame:labelFrame];
label.text = self.headerText;
- (UILabel *)headerFooterLabelWithText:(NSString *)text {
UIFont *font = self.headerFooterFont;
CGFloat width = CGRectGetWidth(self.view.frame) - 2 * VTLabelMargin;
CGFloat height = [self heightForLabelWithText:text andWidth:width];
CGRect frame = CGRectMake(VTLabelMargin, VTLabelMargin, width, height);

UILabel *label = [[UILabel alloc] initWithFrame:frame];
label.text = text;
label.font = font;
label.textColor = [UIColor grayColor];
label.backgroundColor = [UIColor clearColor];
if (@available(iOS 13.0, *)) {
label.textColor = [UIColor secondaryLabelColor];
}
else {
label.textColor = [UIColor grayColor];
}
label.numberOfLines = 0;
label.textAlignment = NSTextAlignmentCenter;
label.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin);
if (@available(iOS 10.0, *)) {
label.adjustsFontForContentSizeCategory = YES;
}

return label;
}

- (void)configureHeaderView {
UILabel *label = [self headerFooterLabelWithText:self.headerText];
CGRect headerFrame = CGRectMake(0, 0, CGRectGetWidth(self.view.frame), CGRectGetHeight(label.frame) + 2 * VTLabelMargin);
UIView *headerView = [[UIView alloc] initWithFrame:headerFrame];
[headerView addSubview:label];
self.tableView.tableHeaderView = headerView;
}

- (void)configureFooterView {
UIFont *font = [self headerFooterFont];
CGFloat labelWidth = CGRectGetWidth(self.view.frame) - 2 * VTLabelMargin;
CGFloat labelHeight = [self heightForLabelWithText:self.footerText andWidth:labelWidth];

CGRect labelFrame = CGRectMake(VTLabelMargin, 0, labelWidth, labelHeight);

UILabel *label = [[UILabel alloc] initWithFrame:labelFrame];
label.text = self.footerText;
label.font = font;
label.textColor = [UIColor grayColor];
label.backgroundColor = [UIColor clearColor];
label.numberOfLines = 0;
label.textAlignment = NSTextAlignmentCenter;
label.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin);
label.userInteractionEnabled = YES;
if (@available(iOS 10.0, *)) {
label.adjustsFontForContentSizeCategory = YES;
}
UILabel *label = [self headerFooterLabelWithText:self.footerText];

if ([self.footerText rangeOfString:[NSURL URLWithString:VTCocoaPodsURLString].host].location != NSNotFound) {
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(openCocoaPodsWebsite:)];
[label addGestureRecognizer:tapGestureRecognizer];
label.userInteractionEnabled = YES;
}

CGRect footerFrame = CGRectMake(0, 0, CGRectGetWidth(label.frame), CGRectGetHeight(label.frame) + VTFooterBottomMargin);
Expand Down Expand Up @@ -273,49 +303,6 @@ - (CGFloat)heightForLabelWithText:(NSString *)labelText andWidth:(CGFloat)labelW
return ceilf(labelHeight);
}

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];

if (self.presentingViewController && self == [self.navigationController.viewControllers firstObject]) {
UIBarButtonItem *doneItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismissViewController:)];
#if !TARGET_OS_TV
self.navigationItem.leftBarButtonItem = doneItem;
#else
// Add a spacer item because the leftBarButtonItem is misplaced on tvOS (doesn't obey the HIG)
UIBarButtonItem *spacerItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
spacerItem.width = 90.0;
self.navigationItem.leftBarButtonItems = @[spacerItem, doneItem];
#endif
}

[self.tableView deselectRowAtIndexPath:self.tableView.indexPathForSelectedRow animated:animated];
}

- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];

if (self.acknowledgements.count == 0) {
NSLog(@"** VTAcknowledgementsViewController Warning **");
NSLog(@"No acknowledgements found.");
NSLog(@"This probably means that you didn’t import the `Pods-acknowledgements.plist` to your main target.");
NSLog(@"Please take a look at https://github.com/vtourraine/VTAcknowledgementsViewController for instructions.");
}
}

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];

[coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
if (self.headerText) {
[self configureHeaderView];
}

if (self.footerText) {
[self configureFooterView];
}
}];
}

#pragma mark - Actions

- (void)openCocoaPodsWebsite:(id)sender {
Expand Down

0 comments on commit 857ad1e

Please sign in to comment.