Apply app styling to a custom view

If you have customised screens in your app, they are not automatically styled with the theme you created in the App Styler tool. You need to make sure your theme is applied to all custom views to ensure a consistent experience for your customers.

Use this guide to apply your App Styler Theme to a custom view.

Before you get started

Make sure you are familiar with the way your app uses the app styler theme you have created:

  • The best place to run styling code from a View Controller is within viewWillAppear.
  • The PoqBaseViewController conforms to Stylable and calls its style() function during viewWillAppear.

Apply app styling

To apply App Styling to your custom view:

  1. Import the foundation framework PoqFoundation, which is used by the platform to adopt App Styling throughout your app's screens:

import PoqFoundation
import UIKit

  1. Make your view adopt Stylable.

class CustomView: UIView, Stylable {
func style() {

  1. Style your subviews within the style function:

func style() {
style(withBackgroundColor: .secondary)
label
.style(withLabelStyle: .title)
.style(withTextColor: .onSecondary)
button
.style(withButtonStyle: .primary)
}

  1. Override your View Controller's style() function to call the custom view's style() function:

class CustomViewController: PoqBaseViewController {
override func style() {
super.style()
customView.style()
}
}

You have applied an app styling theme to your custom view.