Is there any way to apply a style XIB files created by XCode? Something equivalent to styling an HTML file with CSS? I'd like to be able to, say, change the background image for all buttons or for all buttons of a certain class.
(I realize I could probably use XSLT to transform the XIB file or subclass NSButton to set a default background but I'd much rather use a stylesheet type mechanism if one exists)
Thanks, -- James
What are XIB files? From the point of view of the UI designer, XIB files contain the views or windows that you design in Interface Builder – the controls, their layout and properties, and their connections to your code. It is important to understand that on a technical level, XIB files are stored object graphs.
Application interface created with Interface Builder, a graphical editor for designing and testing user interfaces; saved in a text-based flat-file format, introduced in Interface Builder 3.0. NOTE: XIB files are also called "development-time format" files.
The IB file format is an instance of XML, but neither a DTD nor a schema is available. The file content is based on the XML serialization available in Cocoa, which means that some objects are builds in a non-hierarchical manner. It is used for the *. xib files and for designable.
NIBs and XIBs are effectively the same thing: XIBs are newer and are used while you're developing, whereas NIBs are what get produced when you create a build. In modern versions of iOS and macOS, NIBs and XIBs have effectively been replaced by storyboards, although you may still meet them if you work on older projects.
I'm also looking for something similar. I found this which are the closest I could find:
Inspectable:
Ability to add more personalization features to the interface, like round corners, border width, border color... https://www.weheartswift.com/make-awesome-ui-components-ios-8-using-swift-xcode-6/
Afterwards, I created this for buttons as an example:
@IBDesignable public class DesignableButton: UIButton {
@IBInspectable var buttonStyle: String {
set {
switch newValue {
case "green":
layer.frame.size.height = 44
layer.cornerRadius = 22
layer.backgroundColor = UIColor.greenColor().CGColor
case "white":
layer.backgroundColor = UIColor.whiteColor().CGColor
layer.frame.size.height = 44
layer.cornerRadius = 22
default:
break
}
}
}
}
Swift UI:
Haven't tried but seems like a great solution, you can stylize your app using CSS: https://github.com/tombenner/nui
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With