Skip to content

Themed form styling

Last updated: October 20, 2022

If you want to customize your forms beyond what is supported by the default integration, you can apply a theme using the Theme object.

When instantiating a new Theme object, you must supply the following fields at a minimum:

  • primaryFontColor
  • secondaryFontColor
  • buttonFontColor
  • errorFontColor
  • backgroundColor
  • errorBorderColor

You can then optionally provide additional values to customize other elements including button styling, custom placeholder and error text, and field input controls.

Dynamic font sizing based on the user's device is built-in to the Theme object.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Create a new Theme object
var theme = Theme(primaryFontColor: UIColor(red: 0 / 255, green: 204 / 255, blue: 45 / 255, alpha: 1),
secondaryFontColor: UIColor(red: 177 / 255, green: 177 / 255, blue: 177 / 255, alpha: 1),
buttonFontColor: .green,
errorFontColor: .red,
backgroundColor: UIColor(red: 23 / 255, green: 32 / 255, blue: 30 / 255, alpha: 1),
errorBorderColor: .red)
// Add a border and corner radius around text input fields
theme.textInputBackgroundColor = UIColor(red: 36 / 255.0, green: 48 / 255.0, blue: 45 / 255.0, alpha: 1.0)
theme.textInputBorderRadius = 4
// Add a border around input sections
theme.borderRadius = 4
// Create a new payment form style, only providing custom text values
var paymentFormStyle = theme.buildPaymentForm(
headerView: theme.buildPaymentHeader(title: "Payment details",
subtitle: "Accepting your favourite payment methods"),
addBillingButton: theme.buildAddBillingSectionButton(text: "Add billing details",
isBillingAddressMandatory: false,
titleText: "Billing details"),
billingSummary: theme.buildBillingSummary(buttonText: "Change billing details",
titleText: "Billing details"),
cardNumber: theme.buildPaymentInput(isTextFieldNumericInput: true,
titleText: "Card number",
errorText: "Please enter valid card number"),
expiryDate: theme.buildPaymentInput(textFieldPlaceholder: "__ / __",
isTextFieldNumericInput: false,
titleText: "Expiry date",
errorText: "Please enter valid expiry date"),
securityCode: theme.buildPaymentInput(isTextFieldNumericInput: true,
titleText: "CVV date",
errorText: "Please enter valid security code"),
payButton: theme.buildPayButton(text: "Pay now"))
// Override a custom property from the resulting payment form style
paymentFormStyle.payButton.disabledTextColor = UIColor.lightGray
// Create a new billing form style, and modify each field's properties individually
var billingFormStyle = theme.buildBillingForm(
header: theme.buildBillingHeader(title: "Billing information",
cancelButtonTitle: "Cancel",
doneButtonTitle: "Done"),
cells: [.fullName(theme.buildBillingInput(text: "", isNumericInput: false, isMandatory: false, title: "Your name")),
.addressLine1(theme.buildBillingInput(text: "", isNumericInput: false, isMandatory: true, title: "Address")),
.city(theme.buildBillingInput(text: "", isNumericInput: false, isMandatory: true, title: "City")),
.country(theme.buildBillingCountryInput(buttonText: "Select your country", title: "Country")),
.phoneNumber(theme.buildBillingInput(text: "", isNumericInput: true, isMandatory: true, title: "Phone number"))])

See our example project on GitHub.