Thanks to visit codestin.com
Credit goes to github.com

Skip to content

inekipelov/swiftui-superellipse-shape

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Superellipse

Swift Version SPM License Swift Tests
iOS macOS tvOS watchOS

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.

Highlights

  • Configurable curvature via exponent n (ellipse at n=2, progressively squarer as n increases).
  • Deterministic geometry with controllable steps for tessellation.
  • Animatable: n conforms to Animatable.
  • Syntactic sugar: .superellipse and .superellipse(n:steps:) on Shape.

Preview

Superellipse preview

Installation

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")
        ]
    )
]

Usage

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)
    }
}

About

A lightweight SwiftUI `Shape` that implements a superellipse curve

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages