Skip to Content
Docs

Style the card fields

Set the font, colors, border, corners, and padding of the SDK's card inputs, with their own looks while focused or invalid.

PayFieldStyle configures the appearance of the SDK's card fields, including font, text and placeholder colors, background, border, corners, and padding, with separate colors while a field has focus or is invalid. Set it on each field's style. Labels, error text, and the layout around the fields belong to your app. In the drop-in, set PayDropInAppearance.fieldStyle instead.

PayFieldStyle is a struct used on the main actor.

card.number.style = PayFieldStyle(cornerRadius: 12, contentInsets: UIEdgeInsets(top: 14, left: 16, bottom: 14, right: 16))

Parameters

ParameterTypeRequiredDescription
fontUIFontNoThe text and placeholder font. Use a text style font, or one from UIFontMetrics, to follow Dynamic Type. Default: .preferredFont(forTextStyle: .body).
textColorUIColorNoDefault: .label.
placeholderColorUIColorNoDefault: .placeholderText.
invalidTextColorUIColorNoThe text while the field is invalid. Default: .systemRed.
backgroundColorUIColorNoDefault: .secondarySystemBackground.
borderColorUIColorNoDefault: .separator.
focusedBorderColorUIColorNoThe border while the field has focus. Default: .tintColor.
invalidBorderColorUIColorNoThe border while the field is invalid, even with focus. Default: .systemRed.
borderWidthCGFloatNoDefault: 1.
cornerRadiusCGFloatNoDefault: 8.
contentInsetsUIEdgeInsetsNoThe padding around the text. Default: 12 on every side.

Each parameter is also a var, so you can start from PayFieldStyle(), or PayFieldStyle.default, and change a few. A field's height is its font's line height plus the vertical insets, and at least 44 points.

Example

import PayElements
import UIKit

var style = PayFieldStyle()
style.font = UIFontMetrics(forTextStyle: .body).scaledFont(for: UIFont(name: "AvenirNext-Regular", size: 17) ?? .systemFont(ofSize: 17))
style.backgroundColor = .systemBackground
style.borderColor = .systemGray4
style.focusedBorderColor = .systemIndigo
style.cornerRadius = 12

for field in [card.number, card.expiry, card.cvc] as [PayInputField] {
    field.style = style
}
card.name?.style = style

Next steps

Was this page helpful?