Using Swift 5, I am creating gradient backgrounds for the views in a UIPageControl:
var pageControl = UIPageControl()
func configurePageControl() {
self.view.applyGradient(colors: [UIColor.HL.PurpleStart,UIColor.HL.PurpleEnd])
}
Works great...all the pages have this purple gradient background. But when you rotate a device, the gradient rotates but keeps it's original size which is the device frame size in the previous orientation.
So I just want to redraw the gradient when the device is rotated. I use the following method which successfully executes after the device rotation is complete:
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
super.viewWillTransition(to: size, with: coordinator)
coordinator.animate(alongsideTransition: nil, completion: { _ in
self.view.applyGradient(colors: [UIColor.HL.PurpleStart,UIColor.HL.PurpleEnd])
})
}
But this adds a new gradient background underneath the existing one. self.view.applyGradient()
is a more current method of applying gradient backgrounds than other examples on SO, so the other solutions don't seem to apply. So how do you remove/replace the existing gradient when using self.view.applyGradient()
?