VGSCardTextField

@MainActor
public final class VGSCardTextField : VGSTextField

An object that displays an editable text area. Can be use instead of a VGSTextField when need to detect and show credit card brand images.

Overview: VGSCardTextField extends VGSTextField to provide real-time card brand detection (Visa, Mastercard, etc.) and an optional brand icon. It dynamically:

  • Detects card brand as the user types.
  • Updates spacing/formatting pattern automatically.
  • Propagates brand-specific CVC length & formatting to attached VGSCVCTextField.

Usage:

  1. Create instance and assign a VGSConfiguration whose type is .cardNumber (or specialized tokenization configuration).
  2. Optionally customize icon presentation via cardIconLocation, cardIconSize, or supply a closure in cardsIconSource for custom imagery.
  3. Observe field state (state cast to VGSCardState) to access bin, last4, and cardBrand after valid input.

Accessibility:

  • Keep cardIconViewIsAccessibilityElement = true for voiceover users; set cardIconAccessibilityHint to a localized brand description.
  • Avoid adding sensitive PAN information to accessibility hints.

Performance: Brand detection runs on each input change.

Security:

  • No raw PAN characters are logged or exposed via public API.

Enum cases

Attributes

  • Card brand icon position inside VGSCardTextField.

    Declaration

    Swift

    @MainActor
    public var cardIconLocation: VGSCardTextField.CardIconLocation { get set }
  • Card brand icon size. Adjust before heavy layout cycles; changing will update size constraints.

    Declaration

    Swift

    @MainActor
    public var cardIconSize: CGSize { get set }
  • Card Icon accessibility element flag. Set false to hide icon from VoiceOver if redundant.

    Declaration

    Swift

    @MainActor
    public var cardIconViewIsAccessibilityElement: Bool { get set }
  • Card Icon accessibility hint. Provide a localized description of current brand (e.g. “Visa card brand icon”).

    Declaration

    Swift

    @MainActor
    public var cardIconAccessibilityHint: String

Custom card brand images

  • Custom card brand image provider. Return a UIImage for the detected brand or nil to fallback to default asset.

    Declaration

    Swift

    @MainActor
    public var cardsIconSource: ((VGSPaymentCards.CardBrand) -> UIImage?)?
  • The natural size for the Textfield, considering only properties of the view itself plus icon width & height.

    Declaration

    Swift

    @MainActor
    public override var intrinsicContentSize: CGSize { get }