how should i create a border around a swiftui button?
Generated on 8/7/2024
1 search
To create a border around a SwiftUI button, you can use the border
modifier. Here's a simple example:
Button(action: {
// Your action here
}) {
Text("Press me")
}
.border(Color.blue, width: 2)
This code creates a button with a blue border that is 2 points wide.
For more advanced styling, you can use different button styles provided by SwiftUI. For instance, in the session Migrate your TVML app to SwiftUI, it is mentioned that buttons on tvOS use the bordered button style by default, but you can also use the borderless button style for a different appearance.
If you want to learn more about button styles and their adaptivity across different contexts, you can refer to the session SwiftUI essentials.
For creating custom hover effects and more advanced button interactions, you might find the session Create custom hover effects in visionOS useful.
SwiftUI essentials
Join us on a tour of SwiftUI, Apple’s declarative user interface framework. Learn essential concepts for building apps in SwiftUI, like views, state variables, and layout. Discover the breadth of APIs for building fully featured experiences and crafting unique custom components. Whether you’re brand new to SwiftUI or an experienced developer, you’ll learn how to take advantage of what SwiftUI has to offer when building great apps.
Migrate your TVML app to SwiftUI
SwiftUI helps you build great apps on all Apple platforms and is the preferred toolkit for bringing your content into the living room with tvOS 18. Learn how to use SwiftUI to create familiar layouts and controls from TVMLKit, and get tips and best practices.
Create custom hover effects in visionOS
Learn how to develop custom hover effects that update views when people look at them. Find out how to build an expanding button effect that combines opacity, scale, and clip effects. Discover best practices for creating effects that are comfortable and respect people’s accessibility needs.
Meet the Contact Access Button
Learn about the new Contacts authorization modes and how to improve Contacts access in your app. Discover how to integrate the Contact Access Button into your app to share additional contacts on demand and provide an easier path to Contacts authorization. We’ll also cover Contacts security features and an alternative API to be used if the button isn’t appropriate for your app.