TTBaseUILabel
CoreEnhanced 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
| TYPE | FontConfig Key | Small Screen (≤5.8") | Large Screen (>5.8") |
|---|---|---|---|
.HEADER_SUPER | HEADER_SUPER_H | 24pt | 24pt |
.HEADER | HEADER_H | 18pt | 18pt |
.TITLE | TITLE_H | 14pt | 16pt |
.SUB_TITLE | SUB_TITLE_H | 12pt | 14pt |
.SUB_SUB_TILE | SUB_SUB_TITLE_H | 10pt | 12pt |
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
| Method | Returns | Description |
|---|---|---|
setText(text:isBold:) | TTBaseUILabel | Set text, optionally bold |
setBold() | TTBaseUILabel | Apply bold weight |
setRegular() | TTBaseUILabel | Apply regular weight |
setRemiBold() | TTBaseUILabel | Apply semibold weight |
setItalic() | TTBaseUILabel | Apply italic style |
setFont(byWeight:) | TTBaseUILabel | Set any UIFont.Weight |
setAlign(align:) | TTBaseUILabel | Set text alignment |
setTextColor(color:) | TTBaseUILabel | Set text color |
setFontSize(size:) | TTBaseUILabel | Set font point size |
setBgColor(_:) | TTBaseUILabel | Set background color |
setMutilLine(numberOfLine:textAlignment:mode:) | TTBaseUILabel | Enable multiline (0 = unlimited) |
setTouchHandler() | TTBaseUILabel | Enable tap gesture recognizer |
setTextAttr(byText:size:color:) | TTBaseUILabel | Set NSAttributedString text |
addStartRequirement(color:) | TTBaseUILabel | Prefix label text with red asterisk (*) |
addLineAttrSpacing(space:) | TTBaseUILabel | Set line height spacing |
setFullContentHuggingPriority() | TTBaseUILabel | Set content hugging priority to required (1000) |
onAddSkeletonMark() | Void | Show animated skeleton placeholder |
onRemoveSkeletonMark() | Void | Animate 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.