{"id":85,"date":"2022-07-30T11:54:29","date_gmt":"2022-07-30T10:54:29","guid":{"rendered":"https:\/\/techjourney.me\/?p=85"},"modified":"2022-07-30T11:54:29","modified_gmt":"2022-07-30T10:54:29","slug":"swiftui-shapes","status":"publish","type":"post","link":"https:\/\/techjourney.me\/index.php\/2022\/07\/30\/swiftui-shapes\/","title":{"rendered":"SwiftUI Shapes"},"content":{"rendered":"\n

SwiftUI provides the Shape<\/a> protocol which allows developers to create any customs shape they want. It also provides 5 concrete shapes out of the box.<\/p>\n\n\n\n

Built-in Shapes<\/h2>\n\n\n\n

Lets start with the 5 shapes shipped in SwiftUI:<\/p>\n\n\n\n

struct ContentView: View {\n    var body: some View {\n        VStack {\n            Rectangle()\n\n            RoundedRectangle(cornerRadius: 12, style: .continuous)\n                .stroke(lineWidth: 5)\n\n            Ellipse()\n                .fill(.red)\n\n            Capsule()\n                .fill(gradient)\n\n            Circle()\n                .stroke(angularGradient, lineWidth: 5)\n        }\n        .padding()\n    }\n\n\u00a0\u00a0\u00a0\u00a0var gradient: LinearGradient {\n        LinearGradient(\n            colors: [.blue, .purple],\n            startPoint: .leading,\n            endPoint: .trailing\n        )\n    }\n\n    var angularGradient: AngularGradient {\n        AngularGradient(\n            colors: [.blue, .purple],\n            center: .center\n        )\n    }\n}<\/code><\/pre><\/div>\n\n\n\n

The important thing to note here are the configurable options and the default configurations that these shapes take on:<\/p>\n\n\n\n