STPPaymentCardTextField
@IBDesignable
open class STPPaymentCardTextField : UIControl, UIKeyInput, STPFormTextFieldDelegate
STPPaymentCardTextField is a text field with similar properties to UITextField, but specialized for 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
STPPaymentCardTextFieldDelegateDeclaration
Swift
@IBOutlet open weak var delegate: STPPaymentCardTextFieldDelegate?
-
The font used in each child field. Default is
UIFont.systemFont(ofSize:18)
.Declaration
Swift
@objc open var font: UIFont { get set }
-
The text color to be used when entering valid text. Default is
.label
.Declaration
Swift
@objc open 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 open 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 open 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 open var numberPlaceholder: String? { get set }
-
The placeholder for the expiration field. Defaults to “MM/YY”.
Declaration
Swift
@IBInspectable open var expirationPlaceholder: String? { get set }
-
The placeholder for the cvc field. Defaults to “CVC”.
Declaration
Swift
@IBInspectable open 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 open 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 open 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 open var borderColor: UIColor? { get set }
-
The width of the field’s border. Default is 1.0.
Declaration
Swift
@objc open var borderWidth: CGFloat { get set }
-
The corner radius for the field’s border. Default is 5.0.
Declaration
Swift
@objc open var cornerRadius: CGFloat { get set }
-
The keyboard appearance for the field. Default is UIKeyboardAppearanceDefault.
Declaration
Swift
@objc open var keyboardAppearance: UIKeyboardAppearance { get set }
-
This behaves identically to setting the inputView for each child text field.
Declaration
Swift
@objc open override var inputView: UIView? { get set }
-
This behaves identically to setting the inputAccessoryView for each child text field.
Declaration
Swift
@objc open override var inputAccessoryView: UIView? { get set }
-
The curent brand image displayed in the receiver.
Declaration
Swift
@objc open 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
STPCardValidatorDeclaration
Swift
@objc dynamic open var isValid: Bool { get }
-
Enable/disable selecting or editing the field. Useful when submitting card details to Stripe.
Declaration
Swift
@objc open override var isEnabled: Bool { get set }
-
The current card number 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 open var cardNumber: String? { get }
-
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 open 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 open 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 open 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 open var formattedExpirationYear: String? { get }
-
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 open var cvc: String? { get }
-
The current card ZIP or postal code displayed by the field.
Declaration
Swift
@objc open var postalCode: String? { get set }
-
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 open 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. IfpostalCodeEntryEnabled
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 open 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 anSTPPaymentMethodCardParams
object and set this property to that object to prefill the fields you’ve collected. Accessing this property returns a copiedcardParams
. The only way to change properties in this object is to make changes to aSTPPaymentMethodCardParams
you own (retrieved from this text field if desired), and then set this property to the new value.Declaration
Swift
@objc open var cardParams: STPPaymentMethodCardParams { get set }
-
Causes the text field to begin editing. Presents the keyboard.
Seealso
UIResponderDeclaration
Swift
@discardableResult @objc open 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
UIResponderDeclaration
Swift
@discardableResult open 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 open 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:) open 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:) open 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:) open 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:) open 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:) open 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.
-
A SwiftUI representation of an STPPaymentCardTextField.
See moreDeclaration
Swift
public struct Representable : UIViewRepresentable