STPPaymentCardTextField
Objective-C
@interface STPPaymentCardTextField : UIControl <UIKeyInput>
Swift
class STPPaymentCardTextField : UIControl, UIKeyInput
STPPaymentCardTextField is a text field with similar properties to UITextField, but specialized for collecting 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.
-
See
STPPaymentCardTextFieldDelegateDeclaration
Objective-C
@property (nonatomic, weak, nullable) id<STPPaymentCardTextFieldDelegate> delegate;
Swift
@IBOutlet weak var delegate: STPPaymentCardTextFieldDelegate? { get set }
-
The font used in each child field. Default is [UIFont systemFontOfSize:18].
Set this property to nil to reset to the default.
Declaration
Objective-C
@property (nonatomic, copy, null_resettable) UIFont *font;
Swift
@NSCopying var font: UIFont! { get set }
-
The text color to be used when entering valid text. Default is [UIColor labelColor].
Set this property to nil to reset to the default.
Declaration
Objective-C
@property (nonatomic, copy, null_resettable) UIColor *textColor;
Swift
@NSCopying 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 [UIColor redColor]. Set this property to nil to reset to the default.
Declaration
Objective-C
@property (nonatomic, copy, null_resettable) UIColor *textErrorColor;
Swift
@NSCopying 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 [UIColor systemGray2Color]. Set this property to nil to reset to the default.
Declaration
Objective-C
@property (nonatomic, copy, null_resettable) UIColor *placeholderColor;
Swift
@NSCopying 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
Objective-C
@property (nonatomic, copy, nullable) NSString *numberPlaceholder;
Swift
var numberPlaceholder: String? { get set }
-
The placeholder for the expiration field. Defaults to @“MM/YY”.
Declaration
Objective-C
@property (nonatomic, copy, nullable) NSString *expirationPlaceholder;
Swift
var expirationPlaceholder: String? { get set }
-
The placeholder for the cvc field. Defaults to @“CVC”.
Declaration
Objective-C
@property (nonatomic, copy, nullable) NSString *cvcPlaceholder;
Swift
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
Objective-C
@property (nonatomic, copy, nullable) NSString *postalCodePlaceholder;
Swift
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
Objective-C
@property (nonatomic, copy, null_resettable) UIColor *cursorColor;
Swift
@NSCopying var cursorColor: UIColor! { get set }
-
The border color for the field.
Can be nil (in which case no border will be drawn).
Default is [UIColor systemGray2Color].
Declaration
Objective-C
@property (nonatomic, copy, nullable) UIColor *borderColor;
Swift
@NSCopying var borderColor: UIColor? { get set }
-
The width of the field’s border.
Default is 1.0.
Declaration
Objective-C
@property (nonatomic) CGFloat borderWidth;
Swift
var borderWidth: CGFloat { get set }
-
The corner radius for the field’s border.
Default is 5.0.
Declaration
Objective-C
@property (nonatomic) CGFloat cornerRadius;
Swift
var cornerRadius: CGFloat { get set }
-
The keyboard appearance for the field.
Default is UIKeyboardAppearanceDefault.
Declaration
Objective-C
@property (nonatomic) UIKeyboardAppearance keyboardAppearance;
Swift
var keyboardAppearance: UIKeyboardAppearance { get set }
-
This behaves identically to setting the inputView for each child text field.
Declaration
Objective-C
@property (nonatomic, strong, nullable) UIView *inputView;
Swift
var inputView: UIView? { get set }
-
This behaves identically to setting the inputAccessoryView for each child text field.
Declaration
Objective-C
@property (nonatomic, strong, nullable) UIView *inputAccessoryView;
Swift
var inputAccessoryView: UIView? { get set }
-
The curent brand image displayed in the receiver.
Declaration
Objective-C
@property (nonatomic, readonly, nullable) UIImage *brandImage;
Swift
var brandImage: UIImage? { get }
-
Whether or not the form currently contains a valid card number, expiration date, CVC, and postal code (if required).
See
STPCardValidatorDeclaration
Objective-C
@property (nonatomic, readonly) BOOL isValid;
Swift
var isValid: Bool { get }
-
Enable/disable selecting or editing the field. Useful when submitting card details to Stripe.
Declaration
Objective-C
@property (nonatomic, getter=isEnabled) BOOL enabled;
Swift
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
Objective-C
@property (nonatomic, readonly, nullable) NSString *cardNumber;
Swift
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
Objective-C
@property (nonatomic, readonly) NSUInteger expirationMonth;
Swift
var expirationMonth: UInt { 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
Objective-C
@property (nonatomic, readonly, nullable) NSString *formattedExpirationMonth;
Swift
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
Objective-C
@property (nonatomic, readonly) NSUInteger expirationYear;
Swift
var expirationYear: UInt { 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
Objective-C
@property (nonatomic, readonly, nullable) NSString *formattedExpirationYear;
Swift
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
Objective-C
@property (nonatomic, readonly, nullable) NSString *cvc;
Swift
var cvc: String? { get }
-
The current card ZIP or postal code displayed by the field.
Declaration
Objective-C
@property (nonatomic, readonly, nullable) NSString *postalCode;
Swift
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
Objective-C
@property (nonatomic) BOOL postalCodeEntryEnabled;
Swift
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
Objective-C
@property (nonatomic, copy, nullable) NSString *countryCode;
Swift
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 copied
cardParams
. 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
Objective-C
@property (nonatomic, copy, nonnull) STPPaymentMethodCardParams *cardParams;
Swift
@NSCopying var cardParams: STPPaymentMethodCardParams { get set }
-
Causes the text field to begin editing. Presents the keyboard.
See
UIResponderDeclaration
Objective-C
- (BOOL)becomeFirstResponder;
Swift
func becomeFirstResponder() -> Bool
Return Value
Whether or not the text field successfully began editing.
-
Causes the text field to stop editing. Dismisses the keyboard.
See
UIResponderDeclaration
Objective-C
- (BOOL)resignFirstResponder;
Swift
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
Objective-C
- (void)clear;
Swift
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
Objective-C
+ (nullable UIImage *)cvcImageForCardBrand:(STPCardBrand)cardBrand;
Swift
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
Objective-C
+ (nullable UIImage *)brandImageForCardBrand:(STPCardBrand)cardBrand;
Swift
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
Objective-C
+ (nullable UIImage *)errorImageForCardBrand:(STPCardBrand)cardBrand;
Swift
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
Objective-C
- (CGRect)brandImageRectForBounds:(CGRect)bounds;
Swift
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
Objective-C
- (CGRect)fieldsRectForBounds:(CGRect)bounds;
Swift
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.