TTBaseRadioButtonView

Input

Icon + label radio button built on TTIconLabelView. Supports active/inactive states with configurable AwesomePro icons and colors. Default icons are .checkCircle (active) and .circle (inactive). Both icon and label color change together on state toggle.


🚀 Usage

Simple Radio Button

// Active by default
let acceptOption = TTBaseRadioButtonView(isActive: true)
acceptOption.setText(textString: "I agree to terms")

// Inactive by default
let rejectOption = TTBaseRadioButtonView(isActive: false)
rejectOption.setText(textString: "I disagree")

Custom Colors

let premiumOption = TTBaseRadioButtonView(
    isActive: false,
    activeColor: .systemPurple,
    nonActiveColor: .systemGray
)
premiumOption.setText(textString: "Premium Plan")
premiumOption.setOnTouchHandler { view in
    premiumOption.setActive()
    freeOption.setNonActive()
}

Custom Icons (AwesomePro)

let starOption = TTBaseRadioButtonView(
    isActive: false,
    activeIcon: .starFill,
    activeColor: .systemYellow,
    nonActiveIcon: .star,
    nonActiveColor: .systemGray
)
starOption.setText(textString: "Star Plan")

Radio Group Pattern

// Create mutually exclusive group
let options: [(TTBaseRadioButtonView, String)] = [
    (TTBaseRadioButtonView(isActive: true), "Weekly"),
    (TTBaseRadioButtonView(isActive: false), "Monthly"),
    (TTBaseRadioButtonView(isActive: false), "Yearly"),
]

options.enumerated().forEach { i, (btn, title) in
    btn.setText(textString: title)
    btn.setOnTouchHandler { _ in
        options.forEach { $0.0.setNonActive() }  // deselect all
        btn.setActive()                           // select tapped
        selectedPlan = i
    }
    stackView.addArrangedSubview(btn)
}

📖 API Reference

MethodDescription
setText(textString:)Set the label text
setActive()Switch to active state (checkmark icon + activeColor)
setNonActive()Switch to inactive state (circle icon + nonActiveColor)
iconImageViewDirect access to the AwesomePro icon image view
textLabelDirect access to the label (inherited from TTIconLabelView)
Pro Tip: Call setOnTouchHandler (inherited from TTIconLabelView) to wire up a tap callback for each radio option. In the handler, deselect all others then call setActive() on the tapped button to simulate a radio group.