FioriButton
@MainActor
public struct FioriButton : View
A control which is able to display different views depending on current tap state and responds to action.
Create a Fiori button by providing an action and different labels depending on states.
FioriButton(action: { state in
print("Button tapped with state: \(state)")
},
label: { state in
switch state {
case .normal:
Text("Normal")
case .highlighted:
HStack {
Image(systemName: "checkmark")
Text("Highlighted")
}
case .selected:
HStack {
Image(systemName: "checkmark")
Text("Selected")
}
default:
Text("Disabled")
}
})
Create a Fiori button with title text.
FioriButton { _ in "Start" }
Style customization
Create a style that conforms to FioriButtonStyle. There are three predefined Fiori button styles: FioriPrimaryButtonStyle, FioriSecondaryButtonStyle, and FioriTertiaryButtonStyle. To set the style to a FioriButton or to a container within which all Fiori buttons should share the same style, use the fioriButtonStyle(_:) modifier.
struct CustomFioriButtonStyle: FioriButtonStyle {
func makeBody(configuration: FioriButtonStyle.Configuration) -> some View {
let color: Color
switch configuration.state {
case .normal:
color = Color.preferredColor(.tintColor)
case .highlighted, .selected:
color = .red
default:
color = Color.preferredColor(.primary3)
}
return configuration.label
.foregroundColor(.white)
.padding(50)
.background(Circle().fill(color))
}
}
To apply these styles to a Button, use PrimaryButtonStyle, SecondaryButtonStyle, and TertiaryButtonStyle instead.
-
Create a fiori button.
Declaration
Swift
@MainActor public init(isSelectionPersistent: Bool = false, action: ((UIControl.State) -> Void)? = nil, @ViewBuilder label: @escaping (UIControl.State) -> any View)Parameters
isSelectionPersistentA boolean value determines whether the selection should be persistent or not.
actionAction triggered when tap on button.
labelA closure that returns a label for each state. For a button with non-persistent selection,
.normal,.disabled,.highlightedare supported. For a button with persistent selection, use.selectedinstead of.highlighted. -
Create a fiori button.
Declaration
Swift
@MainActor public init(isSelectionPersistent: Bool = false, action: ((UIControl.State) -> Void)? = nil, @ViewBuilder label: @escaping (UIControl.State) -> any View = { _ in EmptyView() }, @ViewBuilder image: @escaping (UIControl.State) -> any View = { _ in EmptyView() }, imagePosition: FioriButtonImagePosition = .leading, imageTitleSpacing: CGFloat = 8.0)Parameters
isSelectionPersistentA boolean value determines whether the selection should be persistent or not.
actionAction triggered when tap on button.
labelA closure that returns a label for each state. For a button with non-persistent selection,
.normal,.disabled,.highlightedare supported. For a button with persistent selection, use.selectedinstead of.highlighted.imageImage of the button.
imagePositionPlace the image along the top, leading, bottom, or trailing edge of the button.
imageTitleSpacingSpacing between image and title.
-
Create a fiori button.
Declaration
Swift
@MainActor public init(isSelectionPersistent: Bool = false, title: @escaping (UIControl.State) -> AttributedString, action: ((UIControl.State) -> Void)? = nil)Parameters
isSelectionPersistentA boolean value determines whether the selection should be persistent or not.
actionAction triggered when tap on button.
titleA closure that returns an attributed string for each state. For a button with non-persistent selection,
.normal,.disabled,.highlightedare supported. For a button with persistent selection, use.selectedinstead of.highlighted. -
Create a fiori button.
Declaration
Swift
@MainActor public init(isSelectionPersistent: Bool = false, title: AttributedString, action: ((UIControl.State) -> Void)? = nil)Parameters
isSelectionPersistentA boolean value determines whether the selection should be persistent or not.
actionAction triggered when tap on button.
titleAn attributed string for button label.
-
The content of the button.
Declaration
Swift
@MainActor public var body: some View { get } -
Undocumented
Declaration
Swift
@MainActor init(isSelectionPersistent: Bool = false, action: ((UIControl.State) -> Void)? = nil, title: @escaping (UIControl.State) -> some StringProtocol)