Skip to content

Instantly share code, notes, and snippets.

@amosgyamfi
Created December 25, 2023 04:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amosgyamfi/86c20a8a6b1d354e0c3525bd564ef390 to your computer and use it in GitHub Desktop.
Save amosgyamfi/86c20a8a6b1d354e0c3525bd564ef390 to your computer and use it in GitHub Desktop.
Create different types of rectangular shapes in SwiftUI
//
// CreateRectangularShapes.swift
// ThousandDaysOfSwiftUI
import SwiftUI
struct CreateRectangularShapes: View {
var body: some View {
NavigationStack {
VStack {
// 1. Rectangle
Rectangle()
.frame(width: 100, height: 100)
// 2. Rounded rectangle with corner radius and style
RoundedRectangle(cornerRadius: /*@START_MENU_TOKEN@*/25.0/*@END_MENU_TOKEN@*/, style: .continuous)
.frame(width: 100, height: 100)
// 3. Rounded rectangle with corner size and style
RoundedRectangle(cornerSize: CGSize(width: 20, height: 10), style: .circular)
.frame(width: 100, height: 100)
// 4. Uneven rounded rectangle
UnevenRoundedRectangle(topLeadingRadius: 30, bottomLeadingRadius: 0, bottomTrailingRadius: 30, topTrailingRadius: 0, style: .continuous)
.frame(width: 100, height: 100)
}
.navigationTitle("Creating Rectangular shapes")
.navigationBarTitleDisplayMode(.inline)
}
}
}
#Preview {
CreateRectangularShapes()
.preferredColorScheme(.dark)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment