SwiftUI RoundedRectangle

cilippofilia's avatar
Published Dec 17, 2022
Contribute to Docs

The RoundedRectangle view is a pre-built rectangular shape with rounded corners that is aligned inside the frame of the View containing it.

SwiftUI has several built-in shapes, such as a rectangle, ellipse, and capsule.

  • Learn how to build iOS applications with Swift and SwiftUI and publish them to Apples' App Store.
    • Includes 7 Courses
    • With Certificate
    • Beginner Friendly.
      13 hours
  • A powerful programming language developed by Apple for iOS, macOS, and more.
    • Beginner Friendly.
      12 hours

Syntax

var body: some View {
    RoundedRectangle(cornerRadius: Int)
        Modifiers here
}

Example

The example below displays a cyan colored rectangle, with rounded corners, with a frame of 200 points wide by 50 points high:

var body: some View {
RoundedRectangle(cornerRadius: 15)
.fill(.cyan)
.frame(width: 200, height: 50)
}

This will display the following:

RoundedRectangle

All contributors

Contribute to Docs

Learn SwiftUI on Codecademy

  • Learn how to build iOS applications with Swift and SwiftUI and publish them to Apples' App Store.
    • Includes 7 Courses
    • With Certificate
    • Beginner Friendly.
      13 hours
  • A powerful programming language developed by Apple for iOS, macOS, and more.
    • Beginner Friendly.
      12 hours