ui: add gradient background for create new group button

pull/689/head
Ryan Zhao 3 years ago
parent b8c7199429
commit afd908a64a

@ -74,16 +74,17 @@ final class NewClosedGroupVC: BaseVC, UITableViewDataSource, UITableViewDelegate
private lazy var fadeView: UIView = { private lazy var fadeView: UIView = {
let result = UIView() let result = UIView()
let gradient = Gradients.newClosedGroupVCFade let gradient = Gradients.newClosedGroupVCFade
result.setGradient(gradient, frame: .init(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 40)) result.setHalfWayGradient(
gradient,
frame: .init(
x: 0,
y: 0,
width: UIScreen.main.bounds.width,
height: 150
)
)
result.isUserInteractionEnabled = false result.isUserInteractionEnabled = false
result.set(.height, to: 40) result.set(.height, to: 150)
return result
}()
private lazy var buttonBackgroundView: UIView = {
let result = UIView()
result.backgroundColor = Colors.cellBackground
result.set(.height, to: 60)
return result return result
}() }()
@ -168,19 +169,31 @@ final class NewClosedGroupVC: BaseVC, UITableViewDataSource, UITableViewDelegate
scrollView.set(.width, to: UIScreen.main.bounds.width) scrollView.set(.width, to: UIScreen.main.bounds.width)
scrollView.pin(to: view) scrollView.pin(to: view)
view.addSubview(buttonBackgroundView)
buttonBackgroundView.pin([ UIView.HorizontalEdge.leading, UIView.HorizontalEdge.trailing, UIView.VerticalEdge.bottom ], to: view)
view.addSubview(fadeView) view.addSubview(fadeView)
fadeView.pin(.leading, to: .leading, of: view) fadeView.pin(.leading, to: .leading, of: view)
fadeView.pin(.trailing, to: .trailing, of: view) fadeView.pin(.trailing, to: .trailing, of: view)
fadeView.pin(.bottom, to: .top, of: buttonBackgroundView) fadeView.pin(.bottom, to: .bottom, of: view)
view.addSubview(createGroupButton) view.addSubview(createGroupButton)
createGroupButton.center(.horizontal, in: view) createGroupButton.center(.horizontal, in: view)
createGroupButton.pin(.bottom, to: .bottom, of: view, withInset: -Values.veryLargeSpacing) createGroupButton.pin(.bottom, to: .bottom, of: view, withInset: -Values.veryLargeSpacing)
} }
@objc override internal func handleAppModeChangedNotification(_ notification: Notification) {
super.handleAppModeChangedNotification(notification)
let gradient = Gradients.newClosedGroupVCFade
fadeView.setHalfWayGradient(
gradient,
frame: .init(
x: 0,
y: 0,
width: UIScreen.main.bounds.width,
height: 150
)
) // Re-do the gradient
}
// MARK: - Table View Data Source // MARK: - Table View Data Source
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

@ -16,9 +16,9 @@ public final class Gradient : NSObject {
@objc public extension UIView { @objc public extension UIView {
@objc func setGradient(_ gradient: Gradient, frame: CGRect = UIScreen.main.bounds) { @objc func setGradient(_ gradient: Gradient) {
let layer = CAGradientLayer() let layer = CAGradientLayer()
layer.frame = frame layer.frame = UIScreen.main.bounds
layer.colors = [ gradient.start.cgColor, gradient.end.cgColor ] layer.colors = [ gradient.start.cgColor, gradient.end.cgColor ]
if let existingSublayer = self.layer.sublayers?[0], existingSublayer is CAGradientLayer { if let existingSublayer = self.layer.sublayers?[0], existingSublayer is CAGradientLayer {
self.layer.replaceSublayer(existingSublayer, with: layer) self.layer.replaceSublayer(existingSublayer, with: layer)
@ -26,6 +26,17 @@ public final class Gradient : NSObject {
self.layer.insertSublayer(layer, at: 0) self.layer.insertSublayer(layer, at: 0)
} }
} }
func setHalfWayGradient(_ gradient: Gradient, frame: CGRect = UIScreen.main.bounds) {
let layer = CAGradientLayer()
layer.frame = frame
layer.colors = [ gradient.start.cgColor, gradient.end.cgColor, gradient.end.cgColor ]
if let existingSublayer = self.layer.sublayers?[0], existingSublayer is CAGradientLayer {
self.layer.replaceSublayer(existingSublayer, with: layer)
} else {
self.layer.insertSublayer(layer, at: 0)
}
}
} }
@objc(LKGradients) @objc(LKGradients)

Loading…
Cancel
Save