struct SimpleCanvasExample: View { var body: some View { ZStack { Canvas { context, size in context.stroke( Path(ellipseIn: CGRect(origin: .zero, size: size).insetBy(dx: 5, dy: 5)), with: .color(.orange), lineWidth: 4) } .frame(width: 300, height: 200) .border(Color.blue) Text("DevTechie") .font(.largeTitle) .foregroundColor(.orange) } } }
struct SimpleCanvasExample: View { var body: some View { ZStack { Canvas { context, size in let gradient = Gradient(colors: [.blue, .pink, .orange]) let rect = CGRect(origin: .zero, size: size).insetBy(dx: 5, dy: 5) let path = Path(ellipseIn: rect) context.stroke( path, with: .color(.orange), lineWidth: 10) context.fill(path, with: .linearGradient(gradient, startPoint: rect.origin, endPoint: CGPoint(x: rect.width, y: 0))) } .frame(width: 300, height: 200) Text("DevTechie") .font(.largeTitle) .foregroundColor(.white) } } }
let midPoint = CGPoint(x: size.width/2, y: size.height/2) let text = Text("DevTechie") .font(.largeTitle) .fontWeight(.bold) .foregroundColor(.white)context.draw(text, at: midPoint, anchor: .center)
struct SimpleCanvasExample: View { var body: some View { Canvas { context, size in let gradient = Gradient(colors: [.blue, .pink, .orange]) let rect = CGRect(origin: .zero, size: size).insetBy(dx: 5, dy: 5) let path = Path(ellipseIn: rect) context.stroke( path, with: .color(.orange), lineWidth: 10) context.fill(path, with: .linearGradient(gradient, startPoint: rect.origin, endPoint: CGPoint(x: rect.width, y: 0))) let midPoint = CGPoint(x: size.width/2, y: size.height/2) let text = Text("DevTechie") .font(.largeTitle) .fontWeight(.bold) .foregroundColor(.white) context.draw(text, at: midPoint, anchor: .center) } .frame(width: 300, height: 200) } }
struct SimpleCanvasExample: View { var body: some View { ZStack { Canvas { context, size in let gradient = Gradient(colors: [.blue, .pink, .orange]) let rect = CGRect(origin: .zero, size: size).insetBy(dx: 5, dy: 5) let linearGradient = GraphicsContext.Shading.linearGradient(gradient, startPoint: rect.origin, endPoint: CGPoint(x: rect.width, y: 0)) let midPoint = CGPoint(x: size.width/2, y: size.height/2) let font = Font.custom("Chalkduster", size: 54) var resolvedText = context.resolve(Text("DevTechie").font(font)) resolvedText.shading = linearGradient context.draw(resolvedText, at: midPoint, anchor: .center) } .frame(width: 300, height: 200) } } }
let image = Image(systemName: "globe") context.draw(image, in: rect.insetBy(dx: 50, dy: 20))
struct SimpleCanvasExample: View { var body: some View { Canvas { context, size in let gradient = Gradient(colors: [.blue, .pink, .orange]) let textGradient = Gradient(colors: [.white, .yellow, .white]) let rect = CGRect(origin: .zero, size: size).insetBy(dx: 5, dy: 5) let linearGradient = GraphicsContext.Shading.linearGradient(gradient, startPoint: rect.origin, endPoint: CGPoint(x: rect.width, y: 0)) let textLinearGradient = GraphicsContext.Shading.linearGradient(textGradient, startPoint: rect.origin, endPoint: CGPoint(x: rect.width, y: 0)) let midPoint = CGPoint(x: size.width/2, y: size.height/2) let font = Font.custom("Chalkduster", size: 54) var resolvedText = context.resolve(Text("DevTechie").font(font)) resolvedText.shading = textLinearGradient let path = Path(ellipseIn: rect) context.stroke( path, with: .color(.orange), lineWidth: 10) context.fill(path, with: linearGradient) context.draw(resolvedText, at: midPoint, anchor: .center) context.blendMode = GraphicsContext.BlendMode.softLight let image = Image(systemName: "globe") context.draw(image, in: rect.insetBy(dx: 50, dy: 20)) } .frame(width: 300, height: 200) } }
let image = Image(systemName: "globe") var filterContext = context filterContext.addFilter(GraphicsContext.Filter.blur(radius: 2)) filterContext.draw(image, in: rect.insetBy(dx: 50, dy: 20))
struct SimpleCanvasExample: View { var body: some View { Canvas { context, size in let gradient = Gradient(colors: [.blue, .pink, .orange]) let textGradient = Gradient(colors: [.white, .yellow, .white]) let rect = CGRect(origin: .zero, size: size).insetBy(dx: 5, dy: 5) let linearGradient = GraphicsContext.Shading.linearGradient(gradient, startPoint: rect.origin, endPoint: CGPoint(x: rect.width, y: 0)) let textLinearGradient = GraphicsContext.Shading.linearGradient(textGradient, startPoint: rect.origin, endPoint: CGPoint(x: rect.width, y: 0)) let midPoint = CGPoint(x: size.width/2, y: size.height/2) let font = Font.custom("Chalkduster", size: 54) var resolvedText = context.resolve(Text("DevTechie").font(font)) resolvedText.shading = textLinearGradient let path = Path(ellipseIn: rect) context.stroke( path, with: .color(.orange), lineWidth: 10) context.fill(path, with: linearGradient) context.draw(resolvedText, at: midPoint, anchor: .center) context.blendMode = GraphicsContext.BlendMode.softLight let image = Image(systemName: "globe") var filterContext = context filterContext.addFilter(GraphicsContext.Filter.blur(radius: 5)) filterContext.draw(image, in: rect.insetBy(dx: 50, dy: 20)) } .frame(width: 300, height: 200) } }
let circlePath = Path(ellipseIn: rect.insetBy(dx: 50, dy: 50)) filterContext.clip(to: circlePath)
struct SimpleCanvasExample: View { var body: some View { Canvas { context, size in let gradient = Gradient(colors: [.blue, .pink, .orange]) let textGradient = Gradient(colors: [.white, .yellow, .white]) let rect = CGRect(origin: .zero, size: size).insetBy(dx: 5, dy: 5) let linearGradient = GraphicsContext.Shading.linearGradient(gradient, startPoint: rect.origin, endPoint: CGPoint(x: rect.width, y: 0)) let textLinearGradient = GraphicsContext.Shading.linearGradient(textGradient, startPoint: rect.origin, endPoint: CGPoint(x: rect.width, y: 0)) let midPoint = CGPoint(x: size.width/2, y: size.height/2) let font = Font.custom("Chalkduster", size: 54) var resolvedText = context.resolve(Text("DevTechie").font(font)) resolvedText.shading = textLinearGradient let path = Path(ellipseIn: rect) context.stroke( path, with: .color(.orange), lineWidth: 10) context.fill(path, with: linearGradient) context.draw(resolvedText, at: midPoint, anchor: .center) context.blendMode = GraphicsContext.BlendMode.softLight let image = Image(systemName: "globe") var filterContext = context let circlePath = Path(ellipseIn: rect.insetBy(dx: 50, dy: 50)) filterContext.clip(to: circlePath) filterContext.addFilter(GraphicsContext.Filter.blur(radius: 5)) filterContext.draw(image, in: rect.insetBy(dx: 50, dy: 20)) } .frame(width: 300, height: 200) } }
filterContext.translateBy(x: 1.0, y: -50.0)
struct SimpleCanvasExample: View { var body: some View { Canvas { context, size in let gradient = Gradient(colors: [.blue, .pink, .orange]) let textGradient = Gradient(colors: [.white, .yellow, .white]) let rect = CGRect(origin: .zero, size: size).insetBy(dx: 5, dy: 5) let linearGradient = GraphicsContext.Shading.linearGradient(gradient, startPoint: rect.origin, endPoint: CGPoint(x: rect.width, y: 0)) let textLinearGradient = GraphicsContext.Shading.linearGradient(textGradient, startPoint: rect.origin, endPoint: CGPoint(x: rect.width, y: 0)) let midPoint = CGPoint(x: size.width/2, y: size.height/2) let font = Font.custom("Chalkduster", size: 54) var resolvedText = context.resolve(Text("DevTechie").font(font)) resolvedText.shading = textLinearGradient let path = Path(ellipseIn: rect) context.stroke( path, with: .color(.orange), lineWidth: 10) context.fill(path, with: linearGradient) context.draw(resolvedText, at: midPoint, anchor: .center) context.blendMode = GraphicsContext.BlendMode.softLight let image = Image(systemName: "globe") var filterContext = context filterContext.translateBy(x: 1.0, y: -50.0) filterContext.addFilter(GraphicsContext.Filter.blur(radius: 5)) filterContext.draw(image, in: rect.insetBy(dx: 50, dy: 50)) } .frame(width: 300, height: 200) } }
struct CanvasSymbolView: View { var body: some View { HStack { Image(systemName: "arrow.forward.to.line") VStack { Image(systemName: "arrow.down.to.line") Text("DevTechie") Image(systemName: "arrow.up.to.line") } Image(systemName: "arrow.backward.to.line") } .foregroundColor(.indigo) .font(.largeTitle) .padding() .background { RoundedRectangle(cornerRadius: 20) .fill(LinearGradient(colors: [.blue, .teal, .cyan], startPoint: .top, endPoint: .bottom)) } } }
struct SimpleCanvasExample: View { var body: some View { Canvas { context, size in let midPoint = CGPoint(x: size.width/2, y: size.height/2) let resolvedView = context.resolveSymbol(id: 0)! context.draw(resolvedView, at: midPoint, anchor: .center) } symbols: { CanvasSymbolView() .tag(0) } .frame(width: 300, height: 200) } }
struct SimpleCanvasExample: View { var body: some View { Canvas { context, size in let midPoint = CGPoint(x: size.width/2, y: size.height/2) let resolvedView = context.resolveSymbol(id: 0)! context.draw(resolvedView, at: midPoint, anchor: .center) } symbols: { CanvasSymbolView() .tag(0) } } }struct CanvasSymbolView: View { @State private var animate = true var body: some View { HStack { Image(systemName: "arrow.forward.to.line") VStack { Image(systemName: "arrow.down.to.line") Text("DevTechie") Image(systemName: "arrow.up.to.line") } Image(systemName: "arrow.backward.to.line") } .foregroundColor(.indigo) .font(.largeTitle) .padding() .background { RoundedRectangle(cornerRadius: 20) .fill(LinearGradient(colors: [.blue, .teal, .cyan], startPoint: .top, endPoint: .bottom)) } .rotationEffect(.degrees(animate ? 0 : 360)) .onAppear { withAnimation(.easeInOut(duration: 2).repeatForever(autoreverses: false)) { animate.toggle() } } } }