Tweak UI elements at runtime to find the perfect values
Tweaks lets you make changes to your iOS app while it is running. This is especially useful if you are not sure about the right font size, colors or if you want to hide certain functionallities from some of your testers.
Add DDHTweaks.swift and DDHTweakUserInterface.swift to your project.
Tweak the font size of a label
DDHTweak.value(category: "Main View", collection: "Text", name: "Size", defaultValue: 20, min: 10, max: 40) { tweak in
self.label.font = UIFont.systemFontOfSize(CGFloat(tweak.currentValue!))
}
Build and run the App. In the Simulator go to Hardware/Shake Gesture. Navigate to Main View and change the font size. Touch Done.
If you add an action to a tweak this is run when ever the value is changed.
- Float
- Double
- Bool
- String
- UIColor
Tweaks without an action have to be run to update the value. This means these tweaks have to be defined in viewWillAppear()
or viewDidAppear()
.
let textColor = Tweak.valueForCategory("Main View", collectionName: "Text", name: "Color", defaultValue: UIColor.blackColor())
label.textColor = textColor
let backgroundColor = Tweak.valueForCategory("Main View", collectionName: "Background", name: "Color", defaultValue: UIColor.whiteColor())
view.backgroundColor = backgroundColor
let text = Tweak.valueForCategory("Main View", collectionName: "Text", name: "Text", defaultValue: "Hello")
label.text = text
Dominik Hauser
Thanks to facebook for the Objective-C version of Tweaks that I used as inspiration.
MIT Licence. See the LICENCE file for details.