- July 4, 2025
- Mins Read
import CUIExpandableButton
import SwiftUI
struct ContentView: View {
@State
var expanded: Bool = false
var body: some View {
CUIExpandableButton(
expanded: $expanded,
sfSymbolName: “gearshape.fill”
) {
Text(“My content”)
}
}
}
CUIExpandableButton(
expanded: $expanded
) {
Image(“icon”)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 26, height: 26)
} content: {
Text(“My content”)
}
CUIExpandableButton(
expanded: $expanded,
sfSymbolName: “bell.fill”
) {
Text(“Button with hidden icon”)
.frame(width: 200)
.padding(8)
}
.hideIcon(true)
.title(“More Info”)
CUIExpandableButton(
expanded: $expanded,
sfSymbolName: “bell.fill”
) {
Text(“Button that hides icon when expanded.”)
.frame(width: 200)
.padding(8)
}
.hideIcon(expanded)
.title(“New Message”)
CUIExpandableButton(
expanded: $expanded,
sfSymbolName: “bell.fill”
) {
Text(“Additional actions can be performed when expanding/collpasing”)
.frame(width: 200)
.padding(8)
} action: {
print(“Button was pressed”)
}
CUIExpandableButton(
expanded: $expanded,
sfSymbolName: “envelope.fill”
) {
Text(“My content”)
.frame(width: 200)
.padding(8)
}
.title(“Inbox”)
.subtitle(“5 unread messages”)
CUIExpandableButton(
expanded: $expanded4,
sfSymbolName: “mappin”
) {
Text(“My content”)
.frame(width: 200)
.padding(8)
}
.title(expanded ? “Visit SF!” : nil)
.subtitle(expanded ? “Top attractions” : nil)
CUIExpandableButton(
expanded: $expanded,
sfSymbolName: “exclamationmark.triangle.fill”
) {
Text(“Take up the full space when expanded.”)
.frame(width: 200)
.padding(8)
)
.hideHeader()
CUIExpandableButton(
expanded: $expanded,
sfSymbolName: “exclamationmark.triangle.fill”
) {
Text(“Hide the separator.”)
.frame(width: 200)
.padding(8)
)
.hideSeperator()
.title(expanded ? “Alert!” : nil)
CUIExpandableButton(
expanded: $expanded,
sfSymbolName: “exclamationmark.triangle.fill”
) {
Text(“Hide the close button to control how it’s dismissed yourself.”)
.frame(width: 200)
.padding(8)
)
.hideCloseButton()
.title(expanded ? “Alert!” : nil)
.subtitle(“You need to take action!”)
CUIExpandableButton(
expanded: $expanded,
sfSymbolName: “doc.fill”
) {
Text(“Tinting the background can help the button fit into your UX design.”)
.frame(width: 200)
.padding(8)
)
.backgroundColor(.blue.opacity(0.15))
CUIExpandableButton(
expanded: $expanded,
sfSymbolName: “doc.fill”
) {
Text(“You can use other standard modifiers too!”)
.frame(width: 200)
.padding(8)
.foregroundColor(nil)
)
.standardLayout(title: “Color”, subtitle: “Customization”)
.foregroundColor(.yellow)
Package.swift
file:
dependencies: [
.package(name: “CUIExpandableButton”, url: “https://github.com/robhasacamera/CUIExpandableButton.git”, from: “0.15.1”)
],