Pin
@MainActor
@preconcurrency
struct
Pin
extension
Pin
:
Sendable
,
SendableMetatype
,
View
A SwiftUI view that renders a map pin.
The appearance of the pin, including its background color, border color, scale, and glyph, can be
customized using a Pin.Configuration
object.
Pin
is used internally by Marker3D
s with the .pin
style, and as a SwiftUI view with the Marker
type.
Examples customizing a Pin
for Marker
:
Marker
(
position
:
.
init
(
latitude
:
0
,
longitude
:
0
))
{
Pin
(
configuration
:
.
init
(
backgroundColor
:
.
blue
,
borderColor
:
.
black
))
})
Marker
(
position
:
.
init
(
latitude
:
0
,
longitude
:
0
))
{
Pin
(
configuration
:
.
red
)
})
-
The type of view representing the body of this view.
When you create a custom view, Swift infers this type from your implementation of the required
View/body-swift.propertyproperty.Declaration
Swift
typealias Body = some View -
A configuration that defines the visual properties of a Pin. This type can be used with the
MarkerorMarker3Dtypes to customize the appearance of a pin-style marker.Example usage:
// Create a pin with a red background, black border, and default inner circle glyph. let redPin = Pin . Configuration ( backgroundColor : . red , borderColor : . black ) // Create a pin with a green background and a custom image glyph. let glyphPin = Pin . Configuration ( backgroundColor : . green ) { Image ( systemName : "leaf.fill" ) . resizable () . scaledToFit () . padding ( 2 ) . foregroundStyle ( . white ) } // Use with Marker3D style: Marker3D ( latitude : 0 , longitude : 0 , style : . pin ( redPin )) Marker3D ( latitude : 0 , longitude : 0 , style : . pin ( glyphPin )) Marker3D ( latitude : 0 , longitude : 0 , style : . pin ( . red )) // Use with Marker style: Marker ( position : . init ( latitude : 0 , longitude : 0 )) { Pin ( configuration : redPin ) }) Marker ( position : . init ( latitude : 0 , longitude : 0 )) { Pin ( configuration : glyphPin ) }) Marker ( position : . init ( latitude : 0 , longitude : 0 )) { Pin ( configuration : . red ) })Declaration
Swift
struct Configuration -
The content and behavior of the view.
When you implement a custom view, you must implement a computed
bodyproperty to provide the content for your view. Return a view that’s composed of built-in views that SwiftUI provides, plus other composite views that you’ve already defined:struct MyView : View { var body : some View { Text ( "Hello, World!" ) } }For more information about composing views and a view hierarchy, see doc:Declaring-a-Custom-View .
Declaration
Swift
@MainActor @preconcurrency var body : some View { get } -
Creates a map pin view with a pin configuration.
This type can be used to provide a custom pin view for
Marker.Declaration
Swift
@MainActor @preconcurrency init ( configuration : Pin . Configuration = . init ())Parameters
configurationThe pin configuration to use for the view. Defaults to the default
Pin.Configuration.

