Created
September 9, 2024 20:16
-
-
Save yccheok/19fbc8111e26bb57892b86bfbea65d3d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GradientView: UIView { | |
override class var layerClass: AnyClass { CAGradientLayer.self } | |
override init(frame: CGRect) { | |
super.init(frame: frame) | |
isOpaque = false | |
if let gradient = self.layer as? CAGradientLayer { | |
gradient.startPoint = .init(x: 0.5, y: 0) | |
gradient.endPoint = .init(x: 0.5, y: 1) | |
//gradient.colors = [UIColor.red.cgColor, UIColor.black.cgColor] | |
gradient.locations = [0.0, 0.2, 0.7, 1.0] | |
gradient.colors = [UIColor.clear.cgColor, UIColor.clear.cgColor, UIColor.black.cgColor, UIColor.black.cgColor] | |
} | |
} | |
required init?(coder: NSCoder) { | |
fatalError("init(coder:) has not been implemented") | |
} | |
} | |
class OnboardingViewControllerTemplate: UIViewController { | |
@IBOutlet weak var stackView: UIStackView! | |
@IBOutlet weak var demoImageView: UIImageView! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
} | |
override func viewDidLayoutSubviews() { | |
super.viewDidLayoutSubviews() | |
print(">>>> self.demoImageView.bounds.width \(self.demoImageView.bounds.width)") | |
print(">>>> self.stackView.bounds.width \(self.stackView.bounds.width)") | |
demoImageView.subviews.forEach({ $0.removeFromSuperview() }) | |
let v = GradientView() | |
v.frame = CGRect( | |
x: 0, | |
y: self.demoImageView.bounds.height - 300, | |
width: self.stackView.bounds.width, // ?? bug | |
height: 300 | |
) | |
self.demoImageView.addSubview(v) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment