Posts

Post not yet marked as solved
0 Replies
309 Views
Can someone explain the concept of an Anchor and Anchor.Source to me (from SwiftUI)?
Posted
by uxjon.
Last updated
.
Post not yet marked as solved
6 Replies
27k Views
I need to get the index as a forEach iterates. Normally, I could just use something like:var i = 0 for item in array { //do stuff i += 1 }But this doesn't work with ForEach. I also tried array.enumerated(), but then it won't let me use .identified(by:) for some reason, so it refuses it as a data source.
Posted
by uxjon.
Last updated
.
Post not yet marked as solved
0 Replies
303 Views
I am trying to clip a view to a shape which has the parent view's size (as opposed to the view being clipped). Is this possible?I get an error that _modified_blah_blah can't be converted to a Shape...
Posted
by uxjon.
Last updated
.
Post not yet marked as solved
0 Replies
383 Views
I have a ProgressBar custom view, and I would like the ability to set a custom fill on it. I can figure out how to do this with a color, but I want to be able to specify either a color or a gradient.The problem is that ShapeStyle has an associated type, and there is no TypeErased version that I know of, so I have no way to store the fill.Is there something I am missing, or a better way to do this?struct ProgressBar<S:Shape> : View { var percent:CGFloat var shape:S init(shape:S, percent:CGFloat) { self.percent = percent self.shape = shape } var body: some View { ZStack(alignment: .leading) { Rectangle().fill().relativeSize(width: percent, height: 1.0).clipShape(shape) shape.stroke() } } } extension ProgressBar where S == RoundedRectangle { init(corner:Length, percent:CGFloat) { self.shape = RoundedRectangle(cornerRadius: corner) self.percent = percent } } extension ProgressBar where S == Rectangle { init(percent: CGFloat) { self.shape = Rectangle() self.percent = percent } func cornerRadius(_ radius: Length) -> ProgressBar<RoundedRectangle> { return ProgressBar<RoundedRectangle>(corner: radius, percent: self.percent) } }
Posted
by uxjon.
Last updated
.