TTBaseUILabel

Core

Enhanced UILabel with built-in font sizing via TYPE enum, skeleton loading, attributed text helpers, tap gesture support, and chainable API. Integrates seamlessly with TTBaseUIKit's FontConfig and ViewConfig.


📋 Declaration

open class TTBaseUILabel: UILabel, ViewDrawer, TextDrawer {
    public enum TYPE {
        case HEADER_SUPER   // FontConfig.HEADER_SUPER_H (default: 24pt)
        case HEADER         // FontConfig.HEADER_H (default: 18pt)
        case TITLE          // FontConfig.TITLE_H (default: 14pt / 16pt on large screens)
        case SUB_TITLE      // FontConfig.SUB_TITLE_H (default: 12pt / 14pt)
        case SUB_SUB_TILE   // FontConfig.SUB_SUB_TITLE_H (default: 10pt / 12pt)
        case NONE
    }
    open func updateUI() { }
    public var onTouchHandler: ((_ label: TTBaseUILabel) -> Void)?
}

🔤 Font Type Reference

TYPEFontConfig KeySmall Screen (≤5.8")Large Screen (>5.8")
.HEADER_SUPERHEADER_SUPER_H24pt24pt
.HEADERHEADER_H18pt18pt
.TITLETITLE_H14pt16pt
.SUB_TITLESUB_TITLE_H12pt14pt
.SUB_SUB_TILESUB_SUB_TITLE_H10pt12pt
Font Customization: Override font sizes globally via TTBaseUIKitConfig.withFontConfig(FontConfig(...)) in AppDelegate. All label types pick up the global config automatically.

🚀 Usage

Basic Label with Type

// Header label with centered alignment
let headerLabel = TTBaseUILabel(
    withType: .HEADER,
    text: "Welcome Back",
    align: .center
)

// Subtitle label — uses subtler color automatically
let subtitleLabel = TTBaseUILabel(
    withType: .SUB_TITLE,
    text: "Sign in to continue"
)

Styling Chain API

let priceLabel = TTBaseUILabel(withType: .TITLE)
priceLabel
    .setText(text: "$29.99")
    .setBold()
    .setTextColor(color: .systemGreen)
    .setAlign(align: .right)
    .done()

Multi-line Label

let descLabel = TTBaseUILabel(withType: .TITLE, text: "Long description...")
descLabel.setMutilLine(numberOfLine: 0, textAlignment: .left)
    .setFontSize(size: 14)
    .done()

Attributed Text

let label = TTBaseUILabel(withType: .TITLE)
label.setTextAttr(byText: "Hello World", size: 16, color: .black)
label.addStartRequirement()       // Adds red asterisk "*" as prefix
label.addLineAttrSpacing(space: 4) // Custom line spacing (NSParagraphStyle)

Skeleton Loading

// Show placeholder while loading
nameLabel.onAddSkeletonMark()

// After data arrives
nameLabel.setText(text: user.name)
nameLabel.onRemoveSkeletonMark() // Fades out skeleton with animation

Touch Handling (Tappable Label)

let linkLabel = TTBaseUILabel(withType: .TITLE, text: "Tap here")
linkLabel.setTouchHandler()
linkLabel.setTextColor(color: .systemBlue)
linkLabel.onTouchHandler = { label in
    print("Label tapped: \(label.text ?? "")")
}

Required Field Marker

// Shows "Email *" — the asterisk is red and added as an attributed prefix
let emailLabel = TTBaseUILabel(withType: .SUB_TITLE, text: "Email")
emailLabel.addStartRequirement(color: .systemRed)

📖 API Reference

MethodReturnsDescription
setText(text:isBold:)TTBaseUILabelSet text, optionally bold
setBold()TTBaseUILabelApply bold weight
setRegular()TTBaseUILabelApply regular weight
setRemiBold()TTBaseUILabelApply semibold weight
setItalic()TTBaseUILabelApply italic style
setFont(byWeight:)TTBaseUILabelSet any UIFont.Weight
setAlign(align:)TTBaseUILabelSet text alignment
setTextColor(color:)TTBaseUILabelSet text color
setFontSize(size:)TTBaseUILabelSet font point size
setBgColor(_:)TTBaseUILabelSet background color
setMutilLine(numberOfLine:textAlignment:mode:)TTBaseUILabelEnable multiline (0 = unlimited)
setTouchHandler()TTBaseUILabelEnable tap gesture recognizer
setTextAttr(byText:size:color:)TTBaseUILabelSet NSAttributedString text
addStartRequirement(color:)TTBaseUILabelPrefix label text with red asterisk (*)
addLineAttrSpacing(space:)TTBaseUILabelSet line height spacing
setFullContentHuggingPriority()TTBaseUILabelSet content hugging priority to required (1000)
onAddSkeletonMark()VoidShow animated skeleton placeholder
onRemoveSkeletonMark()VoidAnimate skeleton removal

⚙️ Global Font Config

// In AppDelegate — customize font sizes for all TTBaseUILabel instances
TTBaseUIKitConfig
    .withDefaultConfig()
    .withFontConfig(
        TTBaseUIKitFontConfig(
            HEADER_SUPER_H: 26,
            HEADER_H: 20,
            TITLE_H: 15,
            SUB_TITLE_H: 13,
            SUB_SUB_TITLE_H: 11
        )
    )
    .start()
Pro Tip: Use setFullContentHuggingPriority() to prevent label from stretching in HStack layouts. Combine with setMutilLine(numberOfLine: 0) for dynamic height text.