Hi folks! I'm trying to recreate the Instagram app icon gradient in SwiftUI, and came across this code which replicated it perfectly:
However, as you see, this is using the Core Animation libarary, of which I have absolutely no knowledge, and couldn't possibly translate to SwiftUI Gradient code myself. Maybe I could use UIViewRepresentable? However, I want the resulting view / gradient to conform to ShapeStyle so that I can use it with .fill(_: ShapeStyle) on any Shape I want (I'm actually using a brilliant tool by Quassum Manus to convert SVG code to a SwiftUI Shape).
Many thanks!
Code Block var view = UILabel() view.frame = CGRect(x: 0, y: 0, width: 1024, height: 1024) view.backgroundColor = .white let layer0 = CALayer() layer0.backgroundColor = UIColor(red: 0.881, green: 0.106, blue: 0.496, alpha: 1).cgColor layer0.bounds = view.bounds layer0.position = view.center view.layer.addSublayer(layer0) let layer1 = CAGradientLayer() layer1.colors = [ UIColor(red: 0.259, green: 0.389, blue: 0.874, alpha: 1).cgColor, UIColor(red: 0.835, green: 0.208, blue: 0.522, alpha: 0).cgColor ] layer1.locations = [0.04, 1] layer1.startPoint = CGPoint(x: 0.25, y: 0.5) layer1.endPoint = CGPoint(x: 0.75, y: 0.5) layer1.transform = CATransform3DMakeAffineTransform(CGAffineTransform(a: 0.33, b: 0.9, c: -0.9, d: 0.33, tx: 0.56, ty: -0.16)) layer1.bounds = view.bounds.insetBy(dx: -0.5*view.bounds.size.width, dy: -0.5*view.bounds.size.height) layer1.position = view.center view.layer.addSublayer(layer1) // + some more constraints stuff
However, as you see, this is using the Core Animation libarary, of which I have absolutely no knowledge, and couldn't possibly translate to SwiftUI Gradient code myself. Maybe I could use UIViewRepresentable? However, I want the resulting view / gradient to conform to ShapeStyle so that I can use it with .fill(_: ShapeStyle) on any Shape I want (I'm actually using a brilliant tool by Quassum Manus to convert SVG code to a SwiftUI Shape).
Many thanks!