TTBaseNotificationView

ViewController

An in-app notification/toast view with an icon, title, subtitle, and optional right action button. Supports fixed height or auto-sizing for multi-line content. Used with TTBaseNotificationViewConfig for show/dismiss animations.


🚀 Usage

// Show a success toast
let notification = TTBaseNotificationView(
    withPadding: (16, 8, 16, 8),
    bgColorNotifi: .systemGreen,
    bgPanelView: .clear,
    isAutoVerticalSize: false
)
notification.titleLabel.setText(text: "Success!")
notification.subLabel.setText(text: "Your changes have been saved.")
notification.setHiddenButton()  // No action button in this case

// Add to top of window
view.addSubview(notification)
notification.setLeadingAnchor(constant: 0)
    .setTrailingAnchor(constant: 0)
    .setTopAnchor(constant: 0)

// Auto-dismiss after 3 seconds
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
    UIView.animate(withDuration: 0.3, animations: {
        notification.alpha = 0
    }) { _ in notification.removeFromSuperview() }
}

// Error notification with details
let error = TTBaseNotificationView(
    withPadding: (12, 8, 12, 8),
    bgColorNotifi: .systemRed,
    bgPanelView: .red.withAlphaComponent(0.1),
    isAutoVerticalSize: true
)
error.titleLabel.setText(text: "Connection Error")
error.subLabel.setText(text: "Please check your internet connection and try again.")
error.iconView.image = UIImage(systemName: "wifi.slash")
error.setHiddenButton()

// With action button
notification.buttonRight.setText(text: "Undo").done()
notification.buttonRight.onTouchHandler = { [weak self] _ in
    self?.viewModel.undo()
}

📖 API Reference

MemberTypeDescription
iconViewTTBaseUIImageFontViewLeft icon (default: checkCircle)
titleLabelTTBaseUILabelPrimary notification title
subLabelTTBaseUILabelDetail text (multi-line when isAutoVerticalSize)
buttonRightTTBaseUIButtonRight action button (optional)
setHiddenIcon()MethodHide left icon
setHiddenButton()MethodHide right action button
Pro Tip: For a proper push-down banner animation, add TTBaseNotificationView with its top anchor off-screen (negative y), then animate topConstraint.constant = 0 with spring damping. The TTBaseNotificationViewConfig helper class manages this lifecycle.