Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Demo code of buttonStyle in SwiftUI
struct TokenButtonStyle: ButtonStyle {
/// Global properties
private let styleType: StyleType
private var iconSize: TokenButton.IconSize?
private var backgroundColor: Color?
private var borderStyle: StyleAlias.BorderStyle?
private var textColor: Color?
/// Circle Icon Button
init(iconSize: TokenButton.IconSize,
backgroundColor: BackgroundColor,
border: BorderStyle? = .none) {
// --snip--
}
/// Icon Button
init(iconSize: TokenButton.IconSize) {
// --snip--
}
/// Capsule Button
init(backgroundColor: BackgroundColor, textColor: TextColor) {
// --snip--
}
/// Text Button
init(textColor: TextColor) {
// --snip--
}
/// Rendering Button Style
func makeBody(configuration: Self.Configuration) -> some View {
var renderView: AnyView!
let verticalMargin = CapsuleValue.verticalMargin.rawValue
let horizontalMargin = CapsuleValue.horizontalMargin.rawValue
switch styleType {
case .circleIcon:
renderView = AnyView(configuration.label
// --snip--
)
case .icon:
renderView = AnyView(configuration.label
// --snip--
)
case .capsule:
renderView = AnyView(configuration.label
// --snip--
)
case .text:
renderView = AnyView(configuration.label
// --snip--
)
}
return renderView.opacity(getOpacityValue(configuration.isPressed))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.