Post

Replies

Boosts

Views

Activity

RoundedRectangle
Simple problem, I want a view that consists of a rounded rectangle with a red border and a clear fill. Here is some simple code. For sake of seeing the problem easier, I have removed the fill (and it appears the default fill is black).import SwiftUI struct ContentView: View { var body: some View { RoundedRectangle(cornerRadius: 30) .frame(width: 100, height: 100) .border(Color.red, width: 4) } } #if DEBUG struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } } #endifRun this code, you'll see a black filled rounded rectangle bounded by a red border. However, the border is not rounded, it is a simple rectangle.Is this a bug, or am I missing something?
5
0
4.8k
Aug ’19
Snapshot of a SwiftUI View
I'm wondering if anyone has figured out how to convert a SwiftUI View into an image?I've tried encapsulating a SwiftUI View into a UIHostingController and using the following code:import SwiftUI extension UIView { func image() -> UIImage { let renderer = UIGraphicsImageRenderer(size: self.bounds.size) let image = renderer.image { context in self.drawHierarchy(in: self.bounds, afterScreenUpdates: true) } return image } } extension UIHostingController { func image() -> Image? { guard let view = self.view else { return nil } let image = view.image() return Image(uiImage: image) } } struct RasterizedView<Content: View>: View { var controller: UIHostingController<Content> init(_ content: Content) { self.controller = UIHostingController(rootView: content) } var body: some View { controller.image() } } #if DEBUG struct RasterizedViewTest_Previews: PreviewProvider { static var previews: some View { RasterizedView(Text("TEST")) } } #endifThis code displays nothing. I went into the debugger and looked at the UIHostingController. The view always has width of 0 and a height of 0.I forced the view to load by adding self.loadView() as a first step in UIHostingController.image(), which results in the view having a non-zero size. However, I encountered a new problem: during runtime I receive an error that looks like this:2019-08-17 17:41:08.737684-0400 Form[88020:27394836] [Snapshotting] View (0x7feb3200a420, UIView) drawing with afterScreenUpdates:YES inside CoreAnimation commit is not supported.Does anyone have any experience or advice that might help me solve this problem?
10
1
10k
Aug ’19
Simultaneous Drag and Magnification Gestures
I wrote an application that enables simultaneous rotate and magnification gestures on a rectange. This application worked as expected. When I adapted the same application to enable simultaneous drag and magnification gestures on a rectange, I can either drag the rectangle or resize the rectangle, but I cannot do both.I'm thinking this behavior is normal, because the two gestures are different; that is, drag is a one-finger gesture and magnify is a two-finger gesture. Can someone confirm this behavior for me?If this is indeed working as expected, then how can I drag and resize a view at the same time?
7
1
6.6k
May ’20
Can DocC Generate Documentation for Extensions?
Is there a way to force the documentation compiler to generate documentation for extensions to types outside a package/framework? This is incredibly important, as some packages and frameworks extend types that are part of the Swift Foundation (e.g., extensions to primitive types and collection) and SwiftUI (e.g., view modifiers and environment values).
5
0
2.4k
Jun ’21