DEV Community

Discussion on: How to Make a Button with SwiftUI

Collapse
 
nunez_giovanni profile image
Giovanni Nunez

Do you know how to add, say a border color and / or background color?

I decided to give swiftUI a shot. I just began learning UIKit and AppKit earlier this week 😅 so I am still trying to soak in all the differences from all 3 frameworks.

Collapse
 
maeganwilson_ profile image
Maegan Wilson • Edited

Yes to the border and border color! I'll put a gist together at lunch and link it here. Unfortunately, I'm still playing around with the background color stuff. That's been a little trickier for me to figure out.

Oh fun! Since I don't do any of this for work, I just try to focus on the new stuff and have fun. Hopefully, an app I write will make money some day.

Collapse
 
maeganwilson_ profile image
Maegan Wilson

Here is the code sample:

Button(action: {print("Button was tapped")}) {
    Text("Tap")
}
.border(.blue, width: 3.0, cornerRadius: 10.0)
.padding(.all, 5.0)
Collapse
 
nunez_giovanni profile image
Giovanni Nunez

woohoo. thanks for the example :-)
I just realized you're also from Austin. Hello, and thanks, neighbor!

Thread Thread
 
maeganwilson_ profile image
Maegan Wilson

You're welcome!

Ah that's cool! Howdy!!

Collapse
 
nightsquid7 profile image
Nightsquid7

Awesome thanks! For some reason the apple documentation for border was buried beneath a bunch of links and I missed it. Glad you posted though!

Thread Thread
 
maeganwilson_ profile image
Maegan Wilson

I have a hard time with the Apple Documentation, so I like to share when I find something like that!