Skip to content

A custom SwiftUI shape which mimics Figma's smooth corner rounding for rectangles.

License

Notifications You must be signed in to change notification settings

sachinkmr57/SmoothRoundedRectangle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SmoothRoundedRectangle
license language

Overview

A custom SwiftUI shape which mimics Figma's smooth corner rounding for rectangles. The smoothness value can be anyting between 0 to 100, 0 with completely circular corner radius and 100 with full smoothness. Corners to which rounding has to be applied can be specified as well. The amount of rounding can be even more than half of the smaller dimension of rectangle just like in Figma.

Detail explanation

Article: Parametric corner smoothing in SwiftUI

Usage

Below are few examples:

Uniform radii on all corners with custom smoothing

SmoothRoundedRectangle(radius: 80, smoothness: .custom(100))
    .fill(Color.cyan)
    .frame(width: 240, height: 240)

Uniform radii on selected corners

SmoothRoundedRectangle(radius: 80, corners: [.topLeft, .bottomRight])
    .fill(Color.green)
    .frame(width: 240, height: 80)

Different radii on different corners

SmoothRoundedRectangle(
    topLeft: 80,
    topRight: 20,
    bottomRight: 80,
    bottomLeft: 20,
    smoothness: .iOS)
    .frame(width: 240, height: 120)

Using inside clipShape

ContentView()
    .clipShape(SmoothRoundedRectangle(radius: 12, smoothness: .iOS))

Results and comparison

A comparison of zero smoothness and 60%.

The indigo corner has 60% smoothing and the green one has no smoothing.
Group 7

A comparison of different smoothnesses and comparison with Figma's smoothness.

Comparison

About

A custom SwiftUI shape which mimics Figma's smooth corner rounding for rectangles.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages