I know you can use .cornerRadius()
to round all the corners of a swiftUI view but is there a way to round only specific corners such as the top?
相关问题
- SwiftUI: UIImage (QRCode) does not load after call
- JFX scale image up and down to parent
- In a UIViewControllerRepresentable, how can I pass
- Upper bound of random number generator
- How do you preview a view containing a binding to
相关文章
- SwiftUI ForEach 'identified(by:)' is depre
- Algorithm for maximizing coverage of rectangular a
- Is there a way to hide the new HTML5 spinbox contr
- Can keyboard of type UIKeyboardTypeNamePhonePad be
- PropertyGrid - Possible to have a file/directory s
- SwiftUI automatically scroll to bottom in ScrollVi
- Programming a touch screen application with SWING
- Rounding decimals in nested data structures in Pyt
Using as a custom modifier
You can use it like a normal modifier:
Only if you implement a simple extension on
View
like this:And here is the struct behind this:
You can also use the shape directly as a clipping mask.
There are two options, you can use a
View
with aPath
, or you can create a customShape
. In both cases you can use them standalone, or in a.background(RoundedCorders(...))
Option 1: Using Path + GeometryReader
(more info on GeometryReader: https://swiftui-lab.com/geometryreader-to-the-rescue/)
Option 2: Custom Shape
View Modifiers made it easy:
Example:
Another option (maybe better) is actually to step back to UIKIt for this. Eg: