Skip to content

Commit 9e1643c

Browse files
authored
Merge pull request #505 from funnel20/WkWebView
Add Safe Area constraints and change activity color
2 parents fc0459b + 8e541ae commit 9e1643c

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

Sources/InAppSettingsKit/Controllers/IASKAppSettingsWebViewController.m

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,31 @@ - (id)initWithFile:(NSString*)urlString specifier:(IASKSpecifier*)specifier {
4343
}
4444

4545
- (void)loadView {
46+
// Initialize the webView
4647
self.webView = [[WKWebView alloc] init];
47-
self.webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
48+
self.webView.translatesAutoresizingMaskIntoConstraints = NO; // Disable autoresizing mask for layout constraints
4849
self.webView.navigationDelegate = self;
50+
51+
// Set up the main view
52+
self.view = [[UIView alloc] init];
4953

50-
self.view = self.webView;
54+
// Ensure to define the default background color for the margins, otherwise those will be black:
55+
if (@available(iOS 13.0, *)) {
56+
self.view.backgroundColor = [UIColor systemBackgroundColor];
57+
} else {
58+
// Fallback on earlier versions:
59+
self.view.backgroundColor = [UIColor whiteColor];
60+
}
61+
[self.view addSubview:self.webView];
62+
63+
// Create constraints to match the entire safe area layout:
64+
UILayoutGuide *safeArea = self.view.safeAreaLayoutGuide;
65+
[NSLayoutConstraint activateConstraints:@[
66+
[self.webView.topAnchor constraintEqualToAnchor:safeArea.topAnchor],
67+
[self.webView.bottomAnchor constraintEqualToAnchor:safeArea.bottomAnchor],
68+
[self.webView.leadingAnchor constraintEqualToAnchor:safeArea.leadingAnchor],
69+
[self.webView.trailingAnchor constraintEqualToAnchor:safeArea.trailingAnchor]
70+
]];
5171
}
5272

5373
- (void)viewWillAppear:(BOOL)animated {
@@ -57,7 +77,12 @@ - (void)viewWillAppear:(BOOL)animated {
5777
#if TARGET_OS_MACCATALYST || (defined(TARGET_OS_VISION) && TARGET_OS_VISION)
5878
activityIndicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleMedium;
5979
#else
60-
activityIndicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
80+
if (@available(iOS 13.0, *)) {
81+
activityIndicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleMedium;
82+
} else {
83+
// Fallback on earlier versions:
84+
activityIndicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
85+
}
6186
#endif
6287
[activityIndicatorView startAnimating];
6388
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:activityIndicatorView];

0 commit comments

Comments
 (0)