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