SwiftUI Image Components

SwiftUI Core

TTBaseUIKit provides two SwiftUI image components: TTBaseSUIImage for asset/icon images with corner radius and aspect ratio, and TTBaseSUIAsyncImage for URL-based remote images with placeholder and error states.

ClassSourceUse Case
TTBaseSUIImageAsset / AwesomePro iconStatic UI images, icons, badges
TTBaseSUIAsyncImageURL stringRemote images (avatars, product photos)

🖼 TTBaseSUIImage

// From asset name
TTBaseSUIImage(imageName: "hero_banner")
    .scaledToFill()
    .clipped()
    .cornerRadius(12)

// System SF Symbol
TTBaseSUIImage(systemName: "star.fill")
    .foregroundStyle(.yellow)
    .frame(width: 24, height: 24)

// AwesomePro icon
TTBaseSUIImage(awesomeIcon: .bell, color: .systemBlue)
    .frame(width: 32, height: 32)

// Circle avatar
TTBaseSUIImage(imageName: "avatar")
    .scaledToFill()
    .frame(width: 56, height: 56)
    .clipShape(Circle())

// With corner radius
TTBaseSUIImage(imageName: "product_thumb")
    .scaledToFill()
    .frame(width: 80, height: 80)
    .cornerRadius(8)
    .clipped()

🌐 TTBaseSUIAsyncImage

// Basic async image from URL
TTBaseSUIAsyncImage(url: product.imageURLString)
    .scaledToFill()
    .frame(width: 100, height: 100)
    .clipped()
    .cornerRadius(8)

// With placeholder while loading
TTBaseSUIAsyncImage(
    url: user.avatarURL,
    placeholder: Image(systemName: "person.circle.fill")
)
.frame(width: 48, height: 48)
.clipShape(Circle())

// With error fallback
TTBaseSUIAsyncImage(
    url: article.coverImageURL,
    placeholder: Image("placeholder_hero"),
    errorImage: Image("error_placeholder")
)
.scaledToFill()
.frame(height: 200)
.cornerRadius(12)
.clipped()

// In a product card
VStack(alignment: .leading) {
    TTBaseSUIAsyncImage(url: product.imageURL)
        .scaledToFill()
        .frame(height: 160)
        .cornerRadius(10)
        .clipped()

    TTBaseSUIText(text: product.name, type: .TITLE)
    TTBaseSUIText(text: product.price, type: .SUB_TITLE)
}
.frame(width: 150)

📖 API Reference

TTBaseSUIImage

InitDescription
init(imageName:)Load from asset catalog
init(systemName:)SF Symbols
init(awesomeIcon:color:)AwesomePro icon image

TTBaseSUIAsyncImage

ParameterTypeDescription
urlString?URL string for remote image
placeholderImage?Shown while loading
errorImageImage?Shown on load failure
Pro Tip: Use .clipShape(Circle()) instead of .cornerRadius() for perfect circular avatars — it handles odd frame sizes gracefully. Always pair TTBaseSUIAsyncImage with a .frame() constraint to prevent layout jumps during loading.