Triangle Views

Display

TTBaseUIKit provides two triangle-related views: TTBaseTriangleView — a raw upward-pointing triangle (filled with CoreGraphics), and TTBaseWarningArrowView — a ready-made warning callout box with an upward-pointing triangle pointer and a colored message panel below it.


🔺 TTBaseTriangleView

A TTBaseUIView subclass that draws an upward-pointing triangle using UIBezierPath. The triangle fills the entire view frame.

// Default yellow triangle
let arrow = TTBaseTriangleView()
arrow.setWidthAnchor(constant: 20)
arrow.setHeightAnchor(constant: 16)
parentView.addSubview(arrow)

// Custom color triangle
let blueArrow = TTBaseTriangleView(
    bgColor: .systemBlue,
    lineColor: .clear   // border stroke (clear = no border)
)

// Point arrow toward a button (useful for tooltips/popovers)
let tooltip = TTBaseTriangleView(
    bgColor: TTView.labelBgWar,
    lineColor: .clear
)
tooltip.setWidthAnchor(constant: 24)
tooltip.setHeightAnchor(constant: 18)
// Center triangle under the target button
tooltip.centerXAnchor.constraint(equalTo: targetButton.centerXAnchor).isActive = true

⚠️ TTBaseWarningArrowView

A pre-built warning callout composite: a triangle pointer on top + colored rounded panel with a text label below. Useful for form validation messages, tooltips, and contextual hints.

// Simple text warning
let warning = TTBaseWarningArrowView(withTitle: "Please fill in all required fields")
stackView.addArrangedSubview(warning)

// Bold title
let boldWarning = TTBaseWarningArrowView(withTitle: "Invalid email address", isBold: true)

// Custom background color
let customWarning = TTBaseWarningArrowView(bgColor: .systemRed)
customWarning.titleLabel.setText(text: "Failed to connect")

// Attributed text
let attr = NSMutableAttributedString(string: "Error: ")
attr.append(NSAttributedString(string: "Field is required", attributes: [.foregroundColor: UIColor.red]))
let attrWarning = TTBaseWarningArrowView(withAttr: attr)

// Center arrow under a specific field
let fieldWarning = TTBaseWarningArrowView(withTitle: "Email is invalid")
fieldWarning.setArrowCenter(byView: emailField, value: 0)  // center arrow under emailField's center X

📖 API Reference

TTBaseTriangleView

Init / PropertyDescription
init(bgColor:lineColor:)Triangle with specific fill and stroke colors
init()Default yellow triangle

TTBaseWarningArrowView

Property / MethodDescription
titleLabelThe text label inside the panel
arrowViewThe triangle pointer view
setArrowCenter(byView:value:)Align triangle center to another view's centerX
paddingInner text padding (default: P_CONS_DEF × 2; override in subclass)
textColorLabel text color (default: white; override in subclass)
Pro Tip: Use setArrowCenter(byView:value:) to precisely align the triangle pointer below any UI element — perfect for form field validation callouts that point exactly to the problematic field.