Skip to content
This repository was archived by the owner on Feb 5, 2025. It is now read-only.

Commit fa79610

Browse files
Use an image view to set the view background to allow setting both color and image
Also adds support for different scaling options for the background
1 parent 09d51bf commit fa79610

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

WordPressAuthenticator/Authenticator/WordPressAuthenticatorStyles.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,10 @@ public struct WordPressAuthenticatorUnifiedStyle {
250250
/// Style: optional auth Prologue view background image
251251
public let prologueBackgroundImage: UIImage?
252252

253+
/// Style: optional resizing policy for the prologue background image
254+
///
255+
public let prologueBackgroundScaleMode: UIView.ContentMode
256+
253257
/// Style: optional blur effect for the buttons view
254258
public let prologueButtonsBlurEffect: UIBlurEffect?
255259

@@ -279,6 +283,7 @@ public struct WordPressAuthenticatorUnifiedStyle {
279283
prologueButtonsBackgroundColor: UIColor = .clear,
280284
prologueViewBackgroundColor: UIColor? = nil,
281285
prologueBackgroundImage: UIImage? = nil,
286+
prologueBackgroundScaleMode: UIView.ContentMode = .scaleToFill,
282287
prologueButtonsBlurEffect: UIBlurEffect? = nil,
283288
statusBarStyle: UIStatusBarStyle = .default,
284289
navBarBackgroundColor: UIColor,
@@ -295,6 +300,7 @@ public struct WordPressAuthenticatorUnifiedStyle {
295300
self.prologueButtonsBackgroundColor = prologueButtonsBackgroundColor
296301
self.prologueViewBackgroundColor = prologueViewBackgroundColor ?? viewControllerBackgroundColor
297302
self.prologueBackgroundImage = prologueBackgroundImage
303+
self.prologueBackgroundScaleMode = prologueBackgroundScaleMode
298304
self.prologueButtonsBlurEffect = prologueButtonsBlurEffect
299305
self.statusBarStyle = statusBarStyle
300306
self.navBarBackgroundColor = navBarBackgroundColor

WordPressAuthenticator/Signin/LoginPrologueViewController.swift

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ class LoginPrologueViewController: LoginViewController {
1313
var showCancel = false
1414

1515
@IBOutlet private weak var buttonContainerView: UIView!
16-
/// Blur effect on button container view
17-
///
18-
private var blurEffect: UIBlurEffect.Style {
19-
return .systemChromeMaterial
20-
}
2116

2217
/// Constraints on the button view container.
2318
/// Used to adjust the button width in unified views.
@@ -390,8 +385,12 @@ class LoginPrologueViewController: LoginViewController {
390385
}
391386

392387
if let backgroundImage = WordPressAuthenticator.shared.unifiedStyle?.prologueBackgroundImage {
393-
view.layer.contents = backgroundImage.cgImage
394-
}
388+
let backgroundImageView = UIImageView(image: backgroundImage)
389+
backgroundImageView.contentMode = WordPressAuthenticator.shared.unifiedStyle?.prologueBackgroundScaleMode ?? .scaleAspectFill
390+
backgroundImageView.translatesAutoresizingMaskIntoConstraints = false
391+
view.insertSubview(backgroundImageView, at: 0)
392+
view.pinSubviewToAllEdges(backgroundImageView)
393+
}
395394
}
396395

397396
private func setButtonViewControllerBackground() {

0 commit comments

Comments
 (0)