@@ -62,15 +62,15 @@ - (WKWebViewConfiguration*)webViewConfiguration {
6262 configuration.allowsAirPlayForMediaPlayback = YES ; // Media: AirPlay
6363 configuration.allowsInlineMediaPlayback = YES ; // Media: Inline Playback
6464 configuration.allowsPictureInPictureMediaPlayback = YES ; // Media: Picture-in-Picture
65- configuration.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeAll ; // Interaction: For Audio/Video Playback -> Disable automatic start explicitely , since the video will be presented fullscreen after page load.
65+ configuration.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeAll ; // Interaction: For Audio/Video Playback -> Disable automatic start explicitly , since the video will be presented fullscreen after page load.
6666 configuration.dataDetectorTypes = WKDataDetectorTypeAll; // Data Detectors: All
6767 if (@available (iOS 14.0 , *)) {
6868 configuration.defaultWebpagePreferences .allowsContentJavaScript = YES ; // JavaScript: Enabled
6969 }
7070 else {
7171 configuration.preferences .javaScriptEnabled = YES ; // Deprecated since iOS 14.0
7272 }
73- configuration.preferences .javaScriptCanOpenWindowsAutomatically = NO ; // JavaScript: Can Auto-open Windows -> Disable explicitely for security reasons.
73+ configuration.preferences .javaScriptCanOpenWindowsAutomatically = NO ; // JavaScript: Can Auto-open Windows -> Disable explicitly for security reasons.
7474 return configuration;
7575}
7676
@@ -80,11 +80,11 @@ - (void)loadView {
8080
8181 // Ensure to define the default background color for the margins, otherwise those will be black:
8282 if (@available (iOS 13.0 , *)) {
83- self.view .backgroundColor = [ UIColor systemBackgroundColor ] ;
83+ self.view .backgroundColor = UIColor. systemBackgroundColor ;
8484 } else {
85- // Fallback on earlier versions:
86- self.view .backgroundColor = [ UIColor whiteColor ] ;
87- }
85+ // Fallback on earlier versions:
86+ self.view .backgroundColor = UIColor. whiteColor ;
87+ }
8888
8989 // Define default activity indicator:
9090 self.activityIndicatorView = [[UIActivityIndicatorView alloc ] initWithFrame: CGRectMake (0 , 0 , 40 , 20 )];
@@ -140,27 +140,28 @@ - (void)loadView {
140140 self.forwardButton .enabled = NO ;
141141
142142 // Only add buttons when `IASKWebViewShowNavigationalButtons` is enabled:
143- if (self.showNavigationalButtons ) {
144- // Add bar buttons for navigation:
145- NSMutableArray *barButtons = [NSMutableArray arrayWithArray: @[self .forwardButton, self .backButton]];
146-
147- if (!self.showProgress ) {
148- // Add default activity indicator when `IASKWebViewShowProgress` is disabled:
149- [barButtons addObject: [[UIBarButtonItem alloc ] initWithCustomView: self .activityIndicatorView]];
150- }
151-
152- // Add buttons to the right side of the Navigation Bar:
153- self.navigationItem .rightBarButtonItems = barButtons;
154- }
155- else if (!self.showProgress ) {
156- // When optional Progress View is not used, assign default indicator to the right side of the Navigation Bar:
157- self.navigationItem .rightBarButtonItem = [[UIBarButtonItem alloc ] initWithCustomView: self .activityIndicatorView];
158- }
143+ NSMutableArray *barButtons = NSMutableArray .array ;
144+ if (self.showNavigationalButtons ) {
145+ // Add bar buttons for navigation:
146+ [barButtons addObjectsFromArray: @[self .forwardButton, self .backButton]];
147+ }
148+ if (!self.showProgress ) {
149+ // Add default activity indicator when `IASKWebViewShowProgress` is disabled:
150+ UIBarButtonItem *activityBarButtonItem = [[UIBarButtonItem alloc ] initWithCustomView: self .activityIndicatorView];
151+ if (@available (iOS 26.0 , *)) {
152+ activityBarButtonItem.hidesSharedBackground = YES ;
153+ [barButtons addObject: UIBarButtonItem.fixedSpaceItem];
154+ }
155+ [barButtons addObject: activityBarButtonItem];
156+ }
157+ self.navigationItem .rightBarButtonItems = barButtons;
159158
160159 if (self.hideBottomBar ) {
161- // Hide the tab bar when this view is pushed:
160+ // Hide the tab bar when this view is pushed:
162161 self.hidesBottomBarWhenPushed = YES ;
163162 }
163+
164+ self.navigationItem .largeTitleDisplayMode = UINavigationItemLargeTitleDisplayModeNever;
164165}
165166
166167- (void )viewDidLoad {
@@ -178,27 +179,18 @@ - (void)viewDidLoad {
178179 self.webView .findInteractionEnabled = YES ; // Interaction: Find & Replace
179180 }
180181 self.webView .allowsLinkPreview = YES ; // Display: Link Preview
181-
182+
182183 [self .view addSubview: self .webView];
183-
184- // Create constraints to match the entire safe area layout:
185- UILayoutGuide *safeArea = self.view .layoutMarginsGuide ;
186- if (@available (iOS 11.0 , *)) {
187- safeArea = self.view .safeAreaLayoutGuide ;
188- }
189- [NSLayoutConstraint activateConstraints: @[
190- [self .webView.topAnchor constraintEqualToAnchor: safeArea.topAnchor],
191- [self .webView.bottomAnchor constraintEqualToAnchor: safeArea.bottomAnchor],
192- [self .webView.leadingAnchor constraintEqualToAnchor: safeArea.leadingAnchor],
193- [self .webView.trailingAnchor constraintEqualToAnchor: safeArea.trailingAnchor]
194- ]];
195-
196- // Add UIProgressView:
197184 [self .view addSubview: self .progressView];
198185
199- // Create constraints to set it to the top of the webView:
200186 [NSLayoutConstraint activateConstraints: @[
201- [self .progressView.topAnchor constraintEqualToAnchor: self .webView.topAnchor],
187+ [self .webView.topAnchor constraintEqualToAnchor: self .view.topAnchor],
188+ [self .webView.bottomAnchor constraintEqualToAnchor: self .view.bottomAnchor],
189+ [self .webView.leadingAnchor constraintEqualToAnchor: self .view.leadingAnchor],
190+ [self .webView.trailingAnchor constraintEqualToAnchor: self .view.trailingAnchor],
191+
192+ // Create constraints to set progressView to the top of the webView:
193+ [self .progressView.topAnchor constraintEqualToAnchor: self .view.safeAreaLayoutGuide.topAnchor],
202194 [self .progressView.leadingAnchor constraintEqualToAnchor: self .webView.leadingAnchor],
203195 [self .progressView.trailingAnchor constraintEqualToAnchor: self .webView.trailingAnchor]
204196 ]];
@@ -217,6 +209,9 @@ - (void)viewWillLayoutSubviews {
217209 [super viewWillLayoutSubviews ];
218210
219211 self.webView .frame = self.view .bounds ;
212+ if (@available (iOS 15.0 , *)) {
213+ self.webView .underPageBackgroundColor = UIColor.systemBackgroundColor ;
214+ }
220215}
221216
222217- (void )viewWillAppear : (BOOL )animated {
@@ -319,9 +314,9 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
319314}
320315
321316- (void )updateNavigationButtons {
322- // Enable or disable the buttons based on whether the webView can go back/forward:
323- self.backButton .enabled = [ self .webView canGoBack ] ;
324- self.forwardButton .enabled = [ self .webView canGoForward ] ;
317+ // Enable or disable the buttons based on whether the webView can go back/forward:
318+ self.backButton .enabled = self.webView . canGoBack ;
319+ self.forwardButton .enabled = self.webView . canGoForward ;
325320}
326321
327322
@@ -387,7 +382,6 @@ - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigati
387382
388383// Tells the delegate that an error occurred during navigation.
389384- (void )webView : (WKWebView *)webView didFailNavigation : (WKNavigation *)navigation withError : (NSError *)error {
390- // Update buttons:
391385 [self updateNavigationButtons ];
392386}
393387
0 commit comments