STPPaymentCardTextField

@IBDesignable
public class STPPaymentCardTextField : UIControl, UIKeyInput, STPFormTextFieldDelegate

STPPaymentCardTextField is a text field with similar properties to UITextField, but specialized for collectplaceholing credit/debit card information. It manages multiple UITextFields under the hood to collect this information. It’s designed to fit on a single line, and from a design perspective can be used anywhere a UITextField would be appropriate.

  • Seealso

    STPPaymentCardTextFieldDelegate

    Declaration

    Swift

    @IBOutlet
    public weak var delegate: STPPaymentCardTextFieldDelegate?
  • The font used in each child field. Default is UIFont.systemFont(ofSize:18).

    Declaration

    Swift

    @objc
    public var font: UIFont { get set }
  • The text color to be used when entering valid text. Default is .label.

    Declaration

    Swift

    @objc
    public var textColor: UIColor { get set }
  • The text color to be used when the user has entered invalid information, such as an invalid card number. Default is .red.

    Declaration

    Swift

    @objc
    public var textErrorColor: UIColor { get set }
  • The text placeholder color used in each child field. This will also set the color of the card placeholder icon. Default is .systemGray2.

    Declaration

    Swift

    @objc
    public var placeholderColor: UIColor { get set }
  • The placeholder for the card number field. Default is “4242424242424242”. If this is set to something that resembles a card number, it will automatically format it as such (in other words, you don’t need to add spaces to this string).

    Declaration

    Swift

    @IBInspectable
    public var numberPlaceholder: String? { get set }
  • The placeholder for the expiration field. Defaults to “MM/YY”.

    Declaration

    Swift

    @IBInspectable
    public var expirationPlaceholder: String? { get set }
  • The placeholder for the cvc field. Defaults to “CVC”.

    Declaration

    Swift

    @IBInspectable
    public var cvcPlaceholder: String? { get set }
  • The placeholder for the postal code field. Defaults to “ZIP” for United States or @“Postal” for all other country codes.

    Declaration

    Swift

    @IBInspectable
    public var postalCodePlaceholder: String? { get set }
  • The cursor color for the field. This is a proxy for the view’s tintColor property, exposed for clarity only (in other words, calling setCursorColor is identical to calling setTintColor).

    Declaration

    Swift

    @objc
    public var cursorColor: UIColor { get set }
  • The border color for the field. Can be nil (in which case no border will be drawn). Default is .systemGray2.

    Declaration

    Swift

    @objc
    public var borderColor: UIColor? { get set }
  • The width of the field’s border. Default is 1.0.

    Declaration

    Swift

    @objc
    public var borderWidth: CGFloat { get set }
  • The corner radius for the field’s border. Default is 5.0.

    Declaration

    Swift

    @objc
    public var cornerRadius: CGFloat { get set }
  • The keyboard appearance for the field. Default is UIKeyboardAppearanceDefault.

    Declaration

    Swift

    @objc
    public var keyboardAppearance: UIKeyboardAppearance { get set }
  • This behaves identically to setting the inputView for each child text field.

    Declaration

    Swift

    @objc
    public override var inputView: UIView? { get set }
  • This behaves identically to setting the inputAccessoryView for each child text field.

    Declaration

    Swift

    @objc
    public override var inputAccessoryView: UIView? { get set }
  • The curent brand image displayed in the receiver.

    Declaration

    Swift

    @objc
    public private(set) var brandImage: UIImage? { get }
  • Whether or not the form currently contains a valid card number, expiration date, CVC, and postal code (if required).

    Seealso

    STPCardValidator

    Declaration

    Swift

    @objc
    dynamic public var isValid: Bool { get }
  • Enable/disable selecting or editing the field. Useful when submitting card details to Stripe.

    Declaration

    Swift

    @objc
    public override var isEnabled: Bool { get set }
  • The current expiration month displayed by the field (1 = January, etc). May or may not be valid, unless isValid is true, in which case it is guaranteed to be valid.

    Declaration

    Swift

    @objc
    public var expirationMonth: Int { get }
  • The current expiration month displayed by the field, as a string. T This may or may not be a valid entry (i.e. “0”) unless isValid is true. It may be also 0-prefixed (i.e. “01” for January).

    Declaration

    Swift

    @objc
    public var formattedExpirationMonth: String? { get }
  • The current expiration year displayed by the field, modulo 100 (e.g. the year 2015 will be represented as 15). May or may not be valid, unless isValid is true, in which case it is guaranteed to be valid.

    Declaration

    Swift

    @objc
    public var expirationYear: Int { get }
  • The current expiration year displayed by the field, as a string. This is a 2-digit year (i.e. “15”), and may or may not be a valid entry unless isValid is true.

    Declaration

    Swift

    @objc
    public var formattedExpirationYear: String? { get }
  • cvc

    The current card CVC displayed by the field. May or may not be valid, unless isValid is true, in which case it is guaranteed to be valid.

    Declaration

    Swift

    @objc
    public var cvc: String? { get }
  • The current card ZIP or postal code displayed by the field.

    Declaration

    Swift

    @objc
    public var postalCode: String? { get }
  • Controls if a postal code entry field can be displayed to the user. Default is YES. If YES, the type of code entry shown is controlled by the set countryCode value. Some country codes may result in no postal code entry being shown if those countries do not commonly use postal codes. If NO, no postal code entry will ever be displayed.

    Declaration

    Swift

    @objc
    public var postalCodeEntryEnabled: Bool { get set }
  • The two-letter ISO country code that corresponds to the user’s billing address. If postalCodeEntryEnabled is YES, this controls which type of entry is allowed. If postalCodeEntryEnabled is NO, this property currently has no effect. If set to nil and postal code entry is enabled, the country from the user’s current locale will be filled in. Otherwise the specific country code set will be used. By default this will fetch the user’s current country code from NSLocale.

    Declaration

    Swift

    @objc
    public var countryCode: String? { get set }
  • Convenience property for creating an STPPaymentMethodCardParams from the currently entered information or programmatically setting the field’s contents. For example, if you’re using another library to scan your user’s credit card with a camera, you can assemble that data into an STPPaymentMethodCardParams object and set this property to that object to prefill the fields you’ve collected. Accessing this property returns a copied cardParams. The only way to change properties in this object is to make changes to a STPPaymentMethodCardParams you own (retrieved from this text field if desired), and then set this property to the new value.

    Declaration

    Swift

    @objc
    public var cardParams: STPPaymentMethodCardParams { get set }
  • Causes the text field to begin editing. Presents the keyboard.

    Seealso

    UIResponder

    Declaration

    Swift

    @discardableResult
    @objc
    public override func becomeFirstResponder() -> Bool

    Return Value

    Whether or not the text field successfully began editing.

  • Causes the text field to stop editing. Dismisses the keyboard.

    Seealso

    UIResponder

    Declaration

    Swift

    @discardableResult
    public override func resignFirstResponder() -> Bool

    Return Value

    Whether or not the field successfully stopped editing.

  • Resets all of the contents of all of the fields. If the field is currently being edited, the number field will become selected.

    Declaration

    Swift

    @objc
    public func clear()
  • Returns the cvc image used for a card brand. Override this method in a subclass if you would like to provide custom images.

    Declaration

    Swift

    @objc(cvcImageForCardBrand:)
    public class func cvcImage(for cardBrand: STPCardBrand) -> UIImage?

    Parameters

    cardBrand

    The brand of card entered.

    Return Value

    The cvc image used for a card brand.

  • Returns the brand image used for a card brand. Override this method in a subclass if you would like to provide custom images.

    Declaration

    Swift

    @objc(brandImageForCardBrand:)
    public class func brandImage(for cardBrand: STPCardBrand)
      -> UIImage?

    Parameters

    cardBrand

    The brand of card entered.

    Return Value

    The brand image used for a card brand.

  • Returns the error image used for a card brand. Override this method in a subclass if you would like to provide custom images.

    Declaration

    Swift

    @objc(errorImageForCardBrand:)
    public class func errorImage(for cardBrand: STPCardBrand)
      -> UIImage?

    Parameters

    cardBrand

    The brand of card entered.

    Return Value

    The error image used for a card brand.

  • Returns the rectangle in which the receiver draws its brand image.

    Declaration

    Swift

    @objc(brandImageRectForBounds:)
    public func brandImageRect(forBounds bounds: CGRect) -> CGRect

    Parameters

    bounds

    The bounding rectangle of the receiver.

    Return Value

    the rectangle in which the receiver draws its brand image.

  • Returns the rectangle in which the receiver draws the text fields.

    Declaration

    Swift

    @objc(fieldsRectForBounds:)
    public func fieldsRect(forBounds bounds: CGRect) -> CGRect

    Parameters

    bounds

    The bounding rectangle of the receiver.

    Return Value

    The rectangle in which the receiver draws the text fields.