Add a shadow to the Swift Button (and also the circle)

・ Reason for writing

I don't use it much, so I will write it for output.


・ The value of cornerRadius should be around 15.0 ~ 20.0 if only the edges are rounded. -ShadowColor is the color of the shadow. Choose your favorite color, gray or black. -Shadow Radius is the roundness of the shadow. I wonder if this should be about 3-5. -ShadowOffset is the size of the shadow. It can be specified by CGSize. -ShadowOpacity is the transparency of the shadow. I'm sorry, this is suitable. Try changing the value.


func ButtuonShadow(position: UIButton){
        //Add a shadow to the button to make it round
        position.layer.cornerRadius = screenWidth/12
        position.layer.shadowColor =
        position.layer.shadowRadius = 3
        position.layer.shadowOffset = CGSize(width: 2, height: 2)
        position.layer.shadowOpacity = 0.5

It seems that there is not much demand, but if you add a lot of buttons. I hope it helps even one person.

Recommended Posts

Add a shadow to the Swift Button (and also the circle)
[Rails] How to create a table, add a column, and change the column type
Extension to add up / down button and finish button to UIToolBar
I want to add a delete function to the comment function
Add a local Swift Package to your project with Swift PM
4 Add println to the interpreter
How to add the same Indexes in a nested array
Click the [rails] button to create a random alphanumeric password and enter it in the password field
[Swift5] How to create a .gitignore file and the code that should be written by default
A story about using the CoreImage framework to erase stains with Swift and implement a blur erase function
I want to create a chat screen for the Swift chat app!
[Swift5] How to get an array and the complement of arrays
[Swift 5] Processing and precautions for transitioning to the iOS settings app
Logic to draw a circle with ASCII art on the console
Method to add the number of years and get the end of the month
[Rails] Add a confirmation screen and a completion screen to devise membership registration.
Add a time stamp to the JAR file name in Gradle
[Swift5] How to communicate from ViewController to Model and pass a value
Add Extended Attributes to the file
How to add columns to a table
[Swift] How to send a notification
How to add the delete function
How to return a value from Model to Controller using the [Swift5] protocol
Add the pre-built jar library to Android and call it in the framework
[Swift] How to connect TabBar with Storyboard Reference and also use NavigationController
[Rails 6] cocoon_ Add id and data attributes to the form to be added
The Android app crashes. Just click a button and it will fall.
[Xcode] How to add a file
[Swift] Copy the character string to the clipboard
Shorten the UUID to base64 in Swift.
[Swift] Converts a UInt64 type integer to [UInt8]
[Swift] A note about function and closure
How to add a new hash / array
[Swift] How to implement the countdown function
A Java engineer compared Swift, Kotlin, and Java.
[Rails] [Memo] When to add = to <%%> and when not
Android Easily give a "press" to a button
How to find the tens and ones
[Swift5] How to create a splash screen
The road to creating a music game 3
Add spring boot and gradle to eclipse
The road to creating a music game 1
[swift] How to control the behavior when the back button of NavigationBar is pressed
If it is Ruby, it is efficient to make it a method and stock the processing.
How to get the ID of a user authenticated with Firebase in Swift
Solves the problem that SwiftPM cannot cross the proxy and cannot add packages to the project
How to find the distance and angle between two points on a plane
I want to recursively get the superclass and interface of a certain class
Introducing what I made when I wanted to add a header and footer to RecyclerView