TTBaseSUIView
CoreA generic container view that wraps any SwiftUI content with configurable background color and corner radius from TTBaseUIKit's config system. The SwiftUI equivalent of TTBaseUIView. iOS 14+ compatible using .cornerRadius().
📋 Declaration
public struct TTBaseSUIView<Content: View>: View {
public var viewDefBgColor: Color // From ViewConfig.viewDefColor
public var viewDefCornerRadius: CGFloat // From SizeConfig.CORNER_RADIUS
public let content: (() -> Content)
public var body: some View {
self.content()
.background(self.viewDefBgColor)
.cornerRadius(self.viewDefCornerRadius) // iOS 14+ compatible
}
}
🔧 Initializers
| Initializer | Description |
|---|---|
init(content:) | Default config — corner + bg auto from SizeConfig / ViewConfig |
init(withCornerRadius:content:) | Custom corner radius, default background |
init(withCornerRadius:bg:content:) | Custom corner radius + custom background color |
🚀 Usage
Basic Container
TTBaseSUIView {
VStack {
Text("Hello, World!")
Text("Welcome to TTBaseUIKit")
}
.padding()
}
Custom Background & Corner Radius
TTBaseSUIView(withCornerRadius: 16, bg: Color.blue) {
VStack {
TTBaseSUIText(withType: .TITLE, text: "Card Title", color: .white)
TTBaseSUIText(withType: .SUB_TITLE, text: "Card subtitle text", color: .white)
}
.padding()
}
Card Pattern with Shadow
TTBaseSUIView(withCornerRadius: 12, bg: Color(.systemBackground)) {
HStack(spacing: 12) {
Image(systemName: "star.fill")
.foregroundColor(.yellow)
VStack(alignment: .leading, spacing: 4) {
TTBaseSUIText(withBold: .TITLE, text: "Featured")
TTBaseSUIText(withType: .SUB_TITLE, text: "New content available")
}
Spacer()
}
.padding(16)
}
.shadow(color: .black.opacity(0.08), radius: 8, x: 0, y: 4)
List Row Container
struct FlightRowView: View {
let flight: Flight
var body: some View {
TTBaseSUIView(withCornerRadius: 8, bg: Color(.secondarySystemBackground)) {
HStack {
VStack(alignment: .leading, spacing: 2) {
TTBaseSUIText(withBold: .TITLE, text: flight.route)
TTBaseSUIText(withType: .SUB_TITLE, text: flight.departureTime)
}
Spacer()
TTBaseSUIText(withBold: .HEADER, text: flight.price)
.foregroundColor(.blue)
}
.padding(.horizontal, 12)
.padding(.vertical, 10)
}
}
}
Full-Width Section Background
// Using default config (reads from ViewConfig automatically)
TTBaseSUIView {
VStack(spacing: 0) {
ForEach(items) { item in
ItemRowView(item: item)
Divider()
}
}
}
⚙️ Config Integration
// TTBaseSUIView reads from the global config automatically:
// viewDefBgColor ← TTView.viewDefColor (from ViewConfig)
// viewDefCornerRadius ← TTSize.CORNER_RADIUS (from SizeConfig)
// Customize in AppDelegate:
TTBaseUIKitConfig
.withDefaultConfig()
.withViewConfig(TTBaseUIKitViewConfig(viewDefColor: UIColor(hex: "#1C1C1E")))
.withSizeConfig(TTBaseUIKitSizeConfig(CORNER_RADIUS: 12))
.start()
iOS 14+:
TTBaseSUIView uses .cornerRadius() which is available on iOS 14+. No need for the iOS 17 .clipShape(.rect(cornerRadius:)) API. This ensures compatibility with all supported deployment targets.
vs UIKit:
TTBaseSUIView is the SwiftUI counterpart of TTBaseUIView. In mixed UIKit/SwiftUI apps (like 12Bay and WECARE 247), both types can be used side-by-side with consistent styling via the shared config system.