Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Demo code of button label in SwiftUI
struct TokenButtonLabel: View {
/// Global properties
private let labelType: LabelTypes
private var iconName: String?
// Icon Type
private var iconSize: TokenButton.IconSize?
init(name: String, iconSize: TokenButton.IconSize) {
self.labelType = .icon
self.iconName = name
self.iconSize = iconSize
// Text Type
private var btnText: String?
init(text: String) {
self.labelType = .text
self.btnText = text
/// Helper function
func getView() -> some View {
var renderView: AnyView!
let highlightSuffix = isHighlighted ? "-highlight" : ""
switch labelType {
case .icon:
let iconString = "\(iconName!)\(highlightSuffix)"
renderView = AnyView(
.aspectRatio(contentMode: .fill)
.frame(width: iconSize!.rawValue, height: iconSize!.rawValue, alignment: .center)
case .text:
renderView = AnyView(
.font(Font.Typography.sizingFont(font: .main, size: .body))
return renderView
// Rendering View
var body: some View {
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.