Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an equivalent to CSS for XIB (XCode Interface Builder XML)?

Tags:

css

xib

themes

skin

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

like image 634
James Williams Avatar asked Dec 14 '11 19:12

James Williams


People also ask

What is an XIB file in Xcode?

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.

Which data format do XIB files use?

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.

What is the use of IB XIB file which is in XML format?

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.

What is difference between NIB and XIB?

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.


1 Answers

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

like image 84
denislexic Avatar answered Oct 05 '22 23:10

denislexic