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 toStylable
and calls itsstyle()
function duringviewWillAppear
.
Apply app styling
To apply App Styling to your custom view:
- Import the foundation framework
PoqFoundation
, which is used by the platform to adopt App Styling throughout your app's screens:
import PoqFoundationimport UIKit
- Make your view adopt
Stylable
.
class CustomView: UIView, Stylable {
func style() {
- Style your subviews within the style function:
func style() { style(withBackgroundColor: .secondary)
label .style(withLabelStyle: .title) .style(withTextColor: .onSecondary)
button .style(withButtonStyle: .primary) }
- Override your View Controller's
style()
function to call the custom view'sstyle()
function:
class CustomViewController: PoqBaseViewController {
override func style() { super.style()
customView.style() }}
You have applied an app styling theme to your custom view.