Skip to content

Commit

Permalink
UI layout unification: NewGameController now has proper support for e…
Browse files Browse the repository at this point in the history
…xtended layout (#371)
  • Loading branch information
herzbube committed Mar 26, 2022
1 parent 46bce48 commit b4c5761
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/newgame/NewGameController.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#import "../ui/AutoLayoutUtility.h"
#import "../ui/TableViewCellFactory.h"
#import "../ui/UiElementMetrics.h"
#import "../ui/UiUtilities.h"
#import "../ui/UIViewControllerAdditions.h"


Expand Down Expand Up @@ -149,8 +148,9 @@ @interface NewGameController()
@property(nonatomic, assign) NewGameModel* theNewGameModel;
@property(nonatomic, assign) PlayerModel* playerModel;
@property(nonatomic, assign) bool advancedScreenWasShown;
@property(nonatomic, assign) UITableView* tableView;
@property(nonatomic, assign) UIView* contentView;
@property(nonatomic, assign) UISegmentedControl* segmentedControl;
@property(nonatomic, assign) UITableView* tableView;
@end


Expand Down Expand Up @@ -287,6 +287,7 @@ - (void) viewWillAppear:(BOOL)animated
// -----------------------------------------------------------------------------
- (void) createSubviews
{
self.contentView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
self.segmentedControl = [[[UISegmentedControl alloc] initWithItems:nil] autorelease];
self.tableView = [[[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped] autorelease];
}
Expand All @@ -296,16 +297,19 @@ - (void) createSubviews
// -----------------------------------------------------------------------------
- (void) setupViewHierarchy
{
[self.view addSubview:self.segmentedControl];
[self.view addSubview:self.tableView];
[self.view addSubview:self.contentView];
[self.contentView addSubview:self.segmentedControl];
[self.contentView addSubview:self.tableView];
}

// -----------------------------------------------------------------------------
/// @brief Private helper for loadView.
// -----------------------------------------------------------------------------
- (void) setupAutoLayoutConstraints
{
self.edgesForExtendedLayout = UIRectEdgeNone;
self.contentView.translatesAutoresizingMaskIntoConstraints = NO;
[AutoLayoutUtility fillSafeAreaOfSuperview:self.view withSubview:self.contentView];

self.segmentedControl.translatesAutoresizingMaskIntoConstraints = NO;
self.tableView.translatesAutoresizingMaskIntoConstraints = NO;
NSDictionary* viewsDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
Expand All @@ -322,15 +326,20 @@ - (void) setupAutoLayoutConstraints
// starting with iOS 8 this default has become 0.
[NSString stringWithFormat:@"V:|-%f-[segmentedControl]-[tableView]-|", [UiElementMetrics verticalSpacingSuperview]],
nil];
[AutoLayoutUtility installVisualFormats:visualFormats withViews:viewsDictionary inView:self.view];
[AutoLayoutUtility installVisualFormats:visualFormats withViews:viewsDictionary inView:self.contentView];
}

// -----------------------------------------------------------------------------
/// @brief Private helper for loadView.
// -----------------------------------------------------------------------------
- (void) configureViews
{
[UiUtilities addGroupTableViewBackgroundToView:self.view];
// self.edgesForExtendedLayout is UIRectEdgeAll, therefore we have to provide
// a background color that is visible behind the navigation bar at the top
// (which on smaller iPhones extends behind the statusbar). Also provides the
// background for the segmented control. Note: We use the same background
// color as the table view to avoid any gaps.
self.view.backgroundColor = self.tableView.backgroundColor;
[self configureSegmentedControl];
[self configureTableView];
[self configureNavigationItem];
Expand Down

0 comments on commit b4c5761

Please sign in to comment.