Custom form styling
Last updated: October 20, 2022
For complete control over how the various UI elements on your forms look, you can use our fully custom solution.
You can use the properties listed in the structs
below to edit each individual UI component displayed across the forms:
1private enum Constants {2 static let mainFontColor = UIColor(red: 0 / 255, green: 204 / 255, blue: 45 / 255, alpha: 1)3 static let secondaryFontColor = UIColor(red: 177 / 255, green: 177 / 255, blue: 177 / 255, alpha: 1)4 static let errorColor = UIColor.red5 static let backgroundColor = UIColor(red: 23 / 255, green: 32 / 255, blue: 30 / 255, alpha: 1)6 static let textFieldBackgroundColor = UIColor(red: 36 / 255.0, green: 48 / 255.0, blue: 45 / 255.0, alpha: 1.0)7 static let borderRadius: CGFloat = 48 static let borderWidth: CGFloat = 19}10
11// Main payment form12
13struct PaymentFormStyleCustom1: PaymentFormStyle {14 var backgroundColor: UIColor = Constants.backgroundColor15 var headerView: PaymentHeaderCellStyle = StyleOrganiser.PaymentHeaderViewStyle()16 var addBillingSummary: CellButtonStyle? = StyleOrganiser.BillingStartButton()17 var editBillingSummary: BillingSummaryViewStyle? = StyleOrganiser.BillingSummaryStyle()18 var cardholderInput: CellTextFieldStyle?19 var cardNumber: CellTextFieldStyle = StyleOrganiser.CardNumberSection()20 var expiryDate: CellTextFieldStyle = StyleOrganiser.ExpiryDateSection()21 var securityCode: CellTextFieldStyle? = StyleOrganiser.SecurityNumberSection()22 var payButton: ElementButtonStyle = StyleOrganiser.PayButtonFormStyleCustom1()23}24
25struct BillingFormStyleCustom1: BillingFormStyle {26 var mainBackground: UIColor = Constants.backgroundColor27 var header: BillingFormHeaderCellStyle = StyleOrganiser.BillingHeaderViewStyle()28 var cells: [BillingFormCell] = [29 .fullName(StyleOrganiser.BillingFullNameInput()),30 .addressLine1(StyleOrganiser.BillingAddressLine1Input()),31 .addressLine2(StyleOrganiser.BillingAddressLine2Input()),32 .city(StyleOrganiser.BillingCityInput()),33 .state(StyleOrganiser.BillingStateInput()),34 .postcode(StyleOrganiser.BillingPostcodeInput()),35 .country(StyleOrganiser.BillingCountryInput()),36 .phoneNumber(StyleOrganiser.BillingPhoneInput())37 ]38}39
40private enum StyleOrganiser {41
42 struct PaymentHeaderViewStyle: PaymentHeaderCellStyle {43 var shouldHideAcceptedCardsList = true44 var backgroundColor: UIColor = Constants.backgroundColor45 var headerLabel: ElementStyle? = PaymentHeaderLabel()46 var subtitleLabel: ElementStyle? = PaymentHeaderSubtitle()47 var schemeIcons: [UIImage?] = []48 }49
50 struct BillingHeaderViewStyle: BillingFormHeaderCellStyle {51 var backgroundColor: UIColor = .clear52 var headerLabel: ElementStyle = BillingHeaderLabel()53 var cancelButton: ElementButtonStyle = CancelButtonStyle()54 var doneButton: ElementButtonStyle = DoneButtonStyle()55 }56
57 struct BillingHeaderLabel: ElementStyle {58 var textAlignment: NSTextAlignment = .natural59 var isHidden = false60 var text: String = "Billing address"61 var font = UIFont(sfMono: .semibold, size: 24)62 var backgroundColor: UIColor = .clear63 var textColor: UIColor = Constants.mainFontColor64 }65
66 struct PayButtonFormStyleCustom1: ElementButtonStyle {67 var image: UIImage?68 var textAlignment: NSTextAlignment = .center69 var text: String = "Pay 100$"70 var font = UIFont.systemFont(ofSize: 15)71 var disabledTextColor: UIColor = Constants.secondaryFontColor72 var disabledTintColor: UIColor = Constants.mainFontColor.withAlphaComponent(0.2)73 var activeTintColor: UIColor = Constants.mainFontColor74 var backgroundColor: UIColor = Constants.mainFontColor75 var textColor: UIColor = .white76 var normalBorderColor: UIColor = .clear77 var focusBorderColor: UIColor = .clear78 var errorBorderColor: UIColor = .clear79 var imageTintColor: UIColor = .clear80 var isHidden = false81 var isEnabled = true82 var height: Double = 5683 var width: Double = 084 var cornerRadius: CGFloat = 1085 var borderWidth: CGFloat = 086 var textLeading: CGFloat = 087 }88
89 struct CancelButtonStyle: ElementButtonStyle {90 var textAlignment: NSTextAlignment = .natural91 var isEnabled = true92 var disabledTextColor: UIColor = Constants.secondaryFontColor93 var disabledTintColor: UIColor = .clear94 var activeTintColor: UIColor = .clear95 var imageTintColor: UIColor = .clear96 var normalBorderColor: UIColor = .clear97 var focusBorderColor: UIColor = .clear98 var errorBorderColor: UIColor = .clear99 var image: UIImage?100 var textLeading: CGFloat = 0101 var cornerRadius: CGFloat = Constants.borderRadius102 var borderWidth: CGFloat = Constants.borderWidth103 var height: Double = 60104 var width: Double = 70105 var isHidden = false106 var text: String = "Cancel"107 var font = UIFont(sfMono: .semibold, size: 17)108 var backgroundColor: UIColor = .clear109 var textColor: UIColor = Constants.mainFontColor110 }111
112 struct DoneButtonStyle: ElementButtonStyle {113 var textAlignment: NSTextAlignment = .natural114 var isEnabled = true115 var disabledTextColor: UIColor = Constants.secondaryFontColor116 var disabledTintColor: UIColor = .clear117 var activeTintColor: UIColor = .clear118 var imageTintColor: UIColor = .clear119 var normalBorderColor: UIColor = .clear120 var focusBorderColor: UIColor = .clear121 var errorBorderColor: UIColor = .clear122 var image: UIImage?123 var textLeading: CGFloat = 0124 var cornerRadius: CGFloat = Constants.borderRadius125 var borderWidth: CGFloat = Constants.borderWidth126 var height: Double = 60127 var width: Double = 70128 var isHidden = false129 var text: String = "Done"130 var font = UIFont(sfMono: .semibold, size: 17)131 var backgroundColor: UIColor = .clear132 var textColor: UIColor = Constants.mainFontColor133 }134
135 struct PaymentHeaderLabel: ElementStyle {136 var textAlignment: NSTextAlignment = .natural137 var isHidden = false138 var text: String = "Payment details"139 var font = UIFont(size: 24)140 var backgroundColor: UIColor = .clear141 var textColor: UIColor = Constants.mainFontColor142 }143
144 struct PaymentHeaderSubtitle: ElementStyle {145 var textAlignment: NSTextAlignment = .natural146 var isHidden = false147 var text: String = "Visa, Mastercard and Maestro accepted."148 var font = UIFont(size: 12)149 var backgroundColor: UIColor = .clear150 var textColor: UIColor = Constants.mainFontColor151 }152
153 struct CardNumberSection: CellTextFieldStyle {154 var isMandatory = true155 var backgroundColor: UIColor = .clear156 var textfield: ElementTextFieldStyle = TextFieldStyle()157 var title: ElementStyle? = TitleStyle(text: "Card number")158 var mandatory: ElementStyle? = MandatoryStyle(text: "")159 var hint: ElementStyle?160 var error: ElementErrorViewStyle? = ErrorViewStyle(text: "Insert a valid card number")161 }162
163 struct ExpiryDateSection: CellTextFieldStyle {164 var textfield: ElementTextFieldStyle = TextFieldStyle(placeholder: "_ _ / _ _")165 var isMandatory = true166 var backgroundColor: UIColor = .clear167 var title: ElementStyle? = TitleStyle(text: "Expiry date")168 var mandatory: ElementStyle? = MandatoryStyle(text: "")169 var hint: ElementStyle?170 var error: ElementErrorViewStyle? = ErrorViewStyle(text: "Insert a valid expiry date")171 }172
173 struct SecurityNumberSection: CellTextFieldStyle {174 var textfield: ElementTextFieldStyle = TextFieldStyle()175 var isMandatory = true176 var backgroundColor: UIColor = .clear177 var title: ElementStyle? = TitleStyle(text: "Security code")178 var mandatory: ElementStyle? = MandatoryStyle(text: "")179 var hint: ElementStyle?180 var error: ElementErrorViewStyle? = ErrorViewStyle(text: "Insert a valid security code")181 }182
183 struct TextFieldStyle: ElementTextFieldStyle {184 var textAlignment: NSTextAlignment = .natural185 var text: String = ""186 var isSupportingNumericKeyboard = true187 var height: Double = 56188 var cornerRadius: CGFloat = Constants.borderRadius189 var borderWidth: CGFloat = Constants.borderWidth190 var placeholder: String?191 var tintColor: UIColor = Constants.mainFontColor192 var normalBorderColor: UIColor = .clear193 var focusBorderColor: UIColor = .clear194 var errorBorderColor: UIColor = Constants.errorColor195 var isHidden = false196 var font = UIFont(size: 15)197 var backgroundColor: UIColor = Constants.textFieldBackgroundColor198 var textColor: UIColor = Constants.mainFontColor199 }200
201 struct TitleStyle: ElementStyle {202 var textAlignment: NSTextAlignment = .natural203 var text: String204 var isHidden = false205 var font = UIFont(size: 15)206 var backgroundColor: UIColor = .clear207 var textColor: UIColor = Constants.mainFontColor208 }209
210 struct MandatoryStyle: ElementStyle {211 var textAlignment: NSTextAlignment = .natural212 var text: String213 var isHidden = false214 var font = UIFont(size: 13)215 var backgroundColor: UIColor = .clear216 var textColor: UIColor = Constants.secondaryFontColor217 }218
219 struct SubtitleElementStyle: ElementStyle {220 var textAlignment: NSTextAlignment = .natural221 var text: String222 var textColor: UIColor = Constants.secondaryFontColor223 var backgroundColor: UIColor = .clear224 var tintColor: UIColor = Constants.mainFontColor225 var image: UIImage?226 var height: Double = 30227 var isHidden = false228 var font = UIFont(size: 13)229 }230
231 struct ErrorViewStyle: ElementErrorViewStyle {232 var textAlignment: NSTextAlignment = .natural233 var text: String234 var textColor: UIColor = Constants.errorColor235 var backgroundColor: UIColor = .clear236 var tintColor: UIColor = Constants.errorColor237 var image: UIImage?238 var height: Double = 30239 var isHidden = true240 var font = UIFont(size: 13)241 }242
243 struct BillingStartButton: CellButtonStyle {244 var isMandatory = true245 var button: ElementButtonStyle = AddBillingDetailsButtonStyle()246 var backgroundColor: UIColor = .red// .clear247 var title: ElementStyle? = TitleStyle(text: "Billing address")248 var mandatory: ElementStyle?249 var hint: ElementStyle? = {250 var element = SubtitleElementStyle(text: "We need this information as an additional security measure to verify this card.")251 element.textColor = Constants.mainFontColor252 return element253 }()254 var error: ElementErrorViewStyle?255 }256
257 struct BillingSummaryStyle: BillingSummaryViewStyle {258 var summary: ElementStyle? = BillingSummaryElementStyle(text: "")259 var cornerRadius: CGFloat = Constants.borderRadius260 var borderWidth: CGFloat = Constants.borderWidth261 var separatorLineColor: UIColor = Constants.secondaryFontColor262 var borderColor: UIColor = Constants.mainFontColor263 var button: ElementButtonStyle = AddBillingDetailsButtonStyle(textLeading: 20, text: "\u{276F} Update Billing Address")264 var isMandatory = true265 var backgroundColor: UIColor = .clear266 var title: ElementStyle? = TitleStyle(text: "Billing address")267 var mandatory: ElementStyle?268 var hint: ElementStyle? = {269 var element = SubtitleElementStyle(text: "We need this information as an additional security measure to verify this card.")270 element.textColor = Constants.mainFontColor271 return element272 }()273 var error: ElementErrorViewStyle?274 }275
276 struct AddBillingDetailsButtonStyle: ElementButtonStyle {277 var textAlignment: NSTextAlignment = .natural278 var isEnabled = true279 var disabledTextColor: UIColor = Constants.secondaryFontColor280 var disabledTintColor: UIColor = Constants.secondaryFontColor281 var activeTintColor: UIColor = Constants.mainFontColor282 var imageTintColor: UIColor = .clear283 var normalBorderColor: UIColor = .clear284 var focusBorderColor: UIColor = .clear285 var errorBorderColor: UIColor = .clear286 var image: UIImage?287 var textLeading: CGFloat = 0288 var cornerRadius: CGFloat = 0289 var borderWidth: CGFloat = 0290 var height: Double = 56291 var width: Double = 300292 var isHidden = false293 var text: String = "\u{276F} Add billing address"294 var font = UIFont(sfMono: .semibold, size: 15)295 var backgroundColor: UIColor = .clear296 var textColor: UIColor = Constants.mainFontColor297 }298
299 struct BillingFullNameInput: CellTextFieldStyle {300 var textfield: ElementTextFieldStyle = TextFieldStyle(isSupportingNumericKeyboard: false)301 var isMandatory = true302 var backgroundColor: UIColor = .clear303 var title: ElementStyle? = TitleStyle(text: "Full name")304 var mandatory: ElementStyle?305 var hint: ElementStyle?306 var error: ElementErrorViewStyle?307 }308
309 struct BillingAddressLine1Input: CellTextFieldStyle {310 var textfield: ElementTextFieldStyle = TextFieldStyle(isSupportingNumericKeyboard: false)311 var isMandatory = true312 var backgroundColor: UIColor = .clear313 var title: ElementStyle? = TitleStyle(text: "Address line 1")314 var mandatory: ElementStyle?315 var hint: ElementStyle?316 var error: ElementErrorViewStyle?317 }318
319 struct BillingAddressLine2Input: CellTextFieldStyle {320 var textfield: ElementTextFieldStyle = TextFieldStyle(isSupportingNumericKeyboard: false)321 var isMandatory = false322 var backgroundColor: UIColor = .clear323 var title: ElementStyle? = TitleStyle(text: "Address line 2")324 var mandatory: ElementStyle? = MandatoryStyle(text: "Optional")325 var hint: ElementStyle?326 var error: ElementErrorViewStyle?327 }328
329 struct BillingCityInput: CellTextFieldStyle {330 var textfield: ElementTextFieldStyle = TextFieldStyle(isSupportingNumericKeyboard: false)331 var isMandatory = true332 var backgroundColor: UIColor = .clear333 var title: ElementStyle? = TitleStyle(text: "City")334 var mandatory: ElementStyle?335 var hint: ElementStyle?336 var error: ElementErrorViewStyle?337 }338
339 struct BillingStateInput: CellTextFieldStyle {340 var textfield: ElementTextFieldStyle = TextFieldStyle(isSupportingNumericKeyboard: false)341 var isMandatory = true342 var backgroundColor: UIColor = .clear343 var title: ElementStyle? = TitleStyle(text: "State")344 var mandatory: ElementStyle?345 var hint: ElementStyle?346 var error: ElementErrorViewStyle?347 }348
349 struct BillingPostcodeInput: CellTextFieldStyle {350 var textfield: ElementTextFieldStyle = TextFieldStyle(isSupportingNumericKeyboard: false)351 var isMandatory = true352 var backgroundColor: UIColor = .clear353 var title: ElementStyle? = TitleStyle(text: "Postcode/Zip")354 var mandatory: ElementStyle?355 var hint: ElementStyle?356 var error: ElementErrorViewStyle?357 }358
359 struct BillingCountryInput: CellButtonStyle {360 var button: ElementButtonStyle = BillingCountryButton()361 var isMandatory = true362 var backgroundColor: UIColor = .clear363 var title: ElementStyle? = TitleStyle(text: "Country")364 var mandatory: ElementStyle?365 var hint: ElementStyle?366 var error: ElementErrorViewStyle?367 }368
369 struct BillingPhoneInput: CellTextFieldStyle {370 var textfield: ElementTextFieldStyle = TextFieldStyle()371 var isMandatory = true372 var backgroundColor: UIColor = .clear373 var title: ElementStyle? = TitleStyle(text: "Phone number")374 var mandatory: ElementStyle?375 var hint: ElementStyle? = SubtitleElementStyle(text: "We will only use this to confirm identity if necessary")376 var error: ElementErrorViewStyle?377 }378
379 struct BillingSummaryElementStyle: ElementStyle {380 var textAlignment: NSTextAlignment = .natural381 var isHidden = false382 var text: String383 var font = UIFont(size: 14)384 var backgroundColor: UIColor = .clear385 var textColor: UIColor = Constants.secondaryFontColor386 }387
388 struct BillingCountryButton: ElementButtonStyle {389 var textAlignment: NSTextAlignment = .natural390 var isEnabled = true391 var disabledTextColor: UIColor = Constants.secondaryFontColor392 var disabledTintColor: UIColor = .clear393 var activeTintColor: UIColor = Constants.mainFontColor394 var imageTintColor: UIColor = Constants.mainFontColor395 var normalBorderColor: UIColor = .clear396 var focusBorderColor: UIColor = .clear397 var errorBorderColor: UIColor = .clear398 var image: UIImage? = UIImage(named: "arrow_green_down")399 var textLeading: CGFloat = 20400 var cornerRadius: CGFloat = Constants.borderRadius401 var borderWidth: CGFloat = 0402 var height: Double = 20403 var width: Double = 80404 var isHidden = false405 var text: String = "Please select a country"406 var font = UIFont(size: 15)407 var backgroundColor: UIColor = Constants.textFieldBackgroundColor408 var textColor: UIColor = Constants.secondaryFontColor409 }410}
See an example on our our GitHub project.