FioriButton
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
public init(isSelectionPersistent: Bool = false, action: ((UIControl.State) -> Void)? = nil, @ViewBuilder label: @escaping (UIControl.State) -> any View)
Parameters
isSelectionPersistent
A boolean value determines whether the selection should be persistent or not.
action
Action triggered when tap on button.
label
A closure that returns a label for each state. For a button with non-persistent selection,
.normal
,.disabled
,.highlighted
are supported. For a button with persistent selection, use.selected
instead of.highlighted
. -
Create a fiori button.
Declaration
Swift
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
isSelectionPersistent
A boolean value determines whether the selection should be persistent or not.
action
Action triggered when tap on button.
label
A closure that returns a label for each state. For a button with non-persistent selection,
.normal
,.disabled
,.highlighted
are supported. For a button with persistent selection, use.selected
instead of.highlighted
.image
Image of the button.
imagePosition
Place the image along the top, leading, bottom, or trailing edge of the button.
imageTitleSpacing
Spacing between image and title.
-
Create a fiori button.
Declaration
Swift
public init(isSelectionPersistent: Bool = false, title: @escaping (UIControl.State) -> AttributedString, action: ((UIControl.State) -> Void)? = nil)
Parameters
isSelectionPersistent
A boolean value determines whether the selection should be persistent or not.
action
Action triggered when tap on button.
title
A closure that returns an attributed string for each state. For a button with non-persistent selection,
.normal
,.disabled
,.highlighted
are supported. For a button with persistent selection, use.selected
instead of.highlighted
. -
Create a fiori button.
Declaration
Swift
public init(isSelectionPersistent: Bool = false, title: AttributedString, action: ((UIControl.State) -> Void)? = nil)
Parameters
isSelectionPersistent
A boolean value determines whether the selection should be persistent or not.
action
Action triggered when tap on button.
title
An attributed string for button label.
-
The content of the button.
Declaration
Swift
public var body: some View { get }
-
Undocumented
Declaration
Swift
init(isSelectionPersistent: Bool = false, action: ((UIControl.State) -> Void)? = nil, title: @escaping (UIControl.State) -> some StringProtocol)