HowTo: Initializing the Property Dictionary - e2technologies/ViewCSS GitHub Wiki
ViewCSS provides a mechanism referred to as "snooping" that will print the values of the different UI elements to the console. This will give the developer a way to quickly initialize the property dictionary.
To turn on snooping, set the "snoop" flag on the ViewCSSManager.
class AppDelegate: UIResponder, UIApplicationDelegate {
override init() {
super.init()
let css: [String:Any] = [
// CSS Properties
]
ViewCSSManager.shared.snoop = true
ViewCSSManager.shared.setCSS(dict: css)
}
}
Turning this on will do 2 things.
Firstly, if a class is specified in the ".css" call but no matching dictionary is found, it will print the name with the current settings of the object. For example
class MyController: UIViewController {
@IBOutlet weak var label1: UILabel?
func viewDidLoad() [
super.viewDidLoad()
self.css(object: self.label1, class: "label")
}
}
will print the following to the console
ViewCSSManager WARN: No match found for CSS class 'label1' referenced from the object of type 'my_controller'
Properties for unknown class my_controller.label1:
- {
"font-size" : "15px",
"text-align" : "left",
"background-color" : "#FFA500FF",
"color" : "#007AFFFF"
}
This is intended to alert you that you specified the use of a class but the library didn't find a match. It will also provide the current values of the UI element so you can populate your property dictionary.
Note that the "ViewCSSManager WARN: No match found..." message prints even if "snoop" is off.
The second thing snoop does is store all of the values and allows you to print them all at once, for example, when the app is backgrounded. This is done by calling the "printSnoop" method.
class AppDelegate: UIResponder, UIApplicationDelegate {
override init() {
super.init()
let css: [String:Any] = [
// CSS Properties
]
ViewCSSManager.shared.snoop = true
ViewCSSManager.shared.setCSS(dict: css)
}
func applicationWillResignActive(_ application: UIApplication) {
ViewCSSManager.shared.printSnoop()
}
}
This will print the entire dictionary in clean JSON to the console.