SwiftUI: Shadow
In this tutorial, we will learn what Shadow is in SwiftUI. You will learn:
- How to use Shadow.
Prerequisites
To follow along with this tutorial, you’ll need some basic knowledge about:
- Swift basics.
- Xcode 11 and above
Shadow
Adding shadow and corner radius is a mess in UIKit, you will need to create two views to achieve that. Below is just one example of including radius and shadow inclusion.
1 2 3 4 5 6 | Rectangle() .fill(Color.green) .cornerRadius(4.0) .shadow(radius: 4.0) .frame(width: 200, height: 200) |
You can adjust the radius of the shadow.
1 2 | .shadow(radius: 20.0) |
You can even move the shadow around with the x and y axes.
1 2 | .shadow(color: Color.blue, radius: 20, x: 50, y: 50) |
SwiftUI: Padding
Padding
Padding automatically adds 16px for each side.
1 2 3 4 5 6 7 8 9 | VStack { Rectangle() .fill(Color.green) .frame(width: 200, height: 200) .padding() .border(Color.red) } |
Perhaps the padding is a bit large. Try changing the padding to 10px.
1 2 | .padding(10.0) |
You can just padding to the left.
1 2 | .padding(.leading, 10) |
You change your mind again and want the padding to the left and right.
1 2 | .padding(.horizontal) |
You can do something a little different.
1 2 | .padding([.leading, .bottom]) |
Thank you for following the next post, hope it will help.
Source: Internet.