- Added the LiveTv Moving View. Converted the timer into animation for the moving view. - Made a Enum with custom functions to handle the time. - Added logic to handle the dark grass for night time - Rescaled the home grass so dark grass and light grass has identical dimensions - Handled the night mode with white text for clear text
52 lines
1.9 KiB
Swift
52 lines
1.9 KiB
Swift
//
|
|
// ApplyGradrient.swift
|
|
// WOKA
|
|
//
|
|
// Created by MacBook Pro on 25/04/24.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
extension UIView {
|
|
|
|
/// Apply gradient colors to the view.
|
|
///
|
|
/// - Parameters:
|
|
/// - colors: An array of UIColor objects defining the color of each gradient stop.
|
|
/// - startPoint: The start point of the gradient, defined in the unit coordinate space. The start point corresponds to the top-left corner of the layer's bounds rectangle.
|
|
/// - endPoint: The end point of the gradient, defined in the unit coordinate space. The end point corresponds to the bottom-right corner of the layer's bounds rectangle.
|
|
///
|
|
func applyGradient(colors: [UIColor], startPoint: CGPoint, endPoint: CGPoint) {
|
|
|
|
// Check if the view already has a gradient layer
|
|
if let sublayers = layer.sublayers {
|
|
for sublayer in sublayers {
|
|
if let gradientLayer = sublayer as? CAGradientLayer {
|
|
// Update the existing gradient layer
|
|
gradientLayer.colors = colors.map { $0.cgColor }
|
|
gradientLayer.startPoint = startPoint
|
|
gradientLayer.endPoint = endPoint
|
|
gradientLayer.frame = bounds
|
|
return
|
|
}
|
|
}
|
|
}
|
|
|
|
// Create a new CAGradientLayer instance
|
|
let gradientLayer = CAGradientLayer()
|
|
|
|
// Set the frame of the gradient layer to match the bounds of the view
|
|
gradientLayer.frame = bounds
|
|
|
|
// Convert the array of UIColor objects to an array of CGColor objects
|
|
gradientLayer.colors = colors.map { $0.cgColor }
|
|
|
|
// Set the start and end points of the gradient
|
|
gradientLayer.startPoint = startPoint
|
|
gradientLayer.endPoint = endPoint
|
|
|
|
// Insert the gradient layer as the bottom layer of the view's layer hierarchy
|
|
layer.insertSublayer(gradientLayer, at: 0)
|
|
}
|
|
}
|