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:
- Create instance and assign a
VGSConfigurationwhosetypeis.cardNumber(or specialized tokenization configuration). - Optionally customize icon presentation via
cardIconLocation,cardIconSize, or supply a closure incardsIconSourcefor custom imagery. - Observe field state (
statecast toVGSCardState) to accessbin,last4, andcardBrandafter valid input.
Accessibility:
- Keep
cardIconViewIsAccessibilityElement = truefor voiceover users; setcardIconAccessibilityHintto 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.
-
Available Card brand icon positions enum.
See moreDeclaration
Swift
public enum CardIconLocation
-
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
falseto 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 image provider. Return a
UIImagefor the detected brand ornilto 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 }
View on GitHub