Learn about drawing using SwiftUI by creating custom controls using a combination of SwiftUI and Core Graphics. Covers shapes, colors, drawing with Pencil, and how to integrate them into a non-trivial app.
Hello,
I had a question about a previous tutorial you did (years ago). It dealt with your “How To Make a Letter / Word Game with UIKit and Swift: Part 1/3” tutorial.
In the app, you used an image for your tiles. I am curious how it would be possible to draw a square or rectangle around the letters using CGRect instead. I am trying with no success.
Again, don’t mean to bring up a question in another tutorial but I didn’t know any other way to contact you.
Thanks!
I loved this training. Is there any way I can get in touch with you about ways that this could be extended to address how to serialize these mind maps in to documents (UIDocument, Codable, and iCloud)
I am working through this course using Xcode 12.5 & IOS 14.5 (Simulator) and I am having a problem in chapter 2-16 with the onTapgesture at line 95 in file ShapeGridView.swift:
even with the provided P02E06 Install Custom Menu end project I am not able to get this piece of code running.
Was there a change preventing this code to run as shown in the video?
Good question!. The shape needs a background color to tap on. Currently there is a stroke around the edge of the shape, so if you tap the edge of the shape, then it works. The center doesn’t have anything to tap!
In ShapesGridView.swift, in ShapesGrid, I would suggest replacing this code at the top of the ForEach in body:
let shape =
self.finalArray[rowIndex][columnIndex].shape
shape
.stroke()
.background(
Color.white
.clipShape(shape)
)
// then it continues with .frame...
This will give the shape a background color of white (try red first so you can see what happens when you clip), and clip it to the same shape.
Thank you.
Now I have encountered another issue:
Performing a device rotation while having the ShapeGridView visible results in a crash because the ForEach Loops are expecting constants and by rotating the device the number of rows and columns are no longer constant.
Here is the exact log:
ForEach<Range, Int, ModifiedContent<HStack<ForEach<Range, Int, ModifiedContent<ModifiedContent<ModifiedContent<ModifiedContent<_StrokedShape, _BackgroundModifier>, _FrameLayout>, _PaddingLayout>, AddGestureModifier<_EndedGesture>>>>, _FrameLayout>> count (1) != its initial count (2). ForEach(_:content:) should only be used for constant data. Instead conform data to Identifiable or use ForEach(_:id:content:) and provide an explicit id!
ForEach<Range, Int, ModifiedContent<ModifiedContent<ModifiedContent<ModifiedContent<_StrokedShape, _BackgroundModifier>, _FrameLayout>, _PaddingLayout>, AddGestureModifier<_EndedGesture>>> count (7) != its initial count (3). ForEach(_:content:) should only be used for constant data. Instead conform data to Identifiable or use ForEach(_:id:content:) and provide an explicit id!
Swift/ContiguousArrayBuffer.swift:580: Fatal error: Index out of range