A lightweight SwiftUI Shape based on the superellipse equation (|x/a|^n + |y/b|^n = 1). Great for buttons, cards, avatars, and other rounded components that feel softer than a rectangle and squarer than an ellipse.
- Configurable curvature via exponent
n(ellipse atn=2, progressively squarer asnincreases). - Deterministic geometry with controllable
stepsfor tessellation. - Animatable:
nconforms toAnimatable. - Syntactic sugar:
.superellipseand.superellipse(n:steps:)onShape.
Add via Swift Package Manager:
dependencies: [
.package(url: "https://github.com/inekipelov/swiftui-superellipse-shape.git", from: "0.0.1")
],
targets: [
.target(
name: "YourTarget",
dependencies: [
.product(name: "Superellipse", package: "swiftui-superellipse-shape")
]
)
]import SwiftUI
import Superellipse
struct ContentView: View {
@State private var curvature: CGFloat = 4.5
var body: some View {
VStack(spacing: 24) {
Superellipse(n: curvature, steps: 256)
.fill(.blue.gradient)
.frame(width: 220, height: 140)
Slider(value: $curvature, in: 2...8) {
Text("Curvature (n)")
}
}
.padding()
.animation(.easeInOut, value: curvature)
}
}