2

I one of my big projects the customer just wished to change leading font in whole app. It is quite simple for the fonts allocated by code (I have some kind of theme system which abstracts font creation).

But the problem starts with the fonts used in XIB files. Do I have to go thorough all of them and apply change to properties manually (I have literally dozens of them)?

Are there any smart terminal commands which could do this in more efficient way (combination of ibtool, xargs, find)?

I have accomplished similar problem - extracting all strings used in XIB as mentioned here:

https://stackoverflow.com/a/7754884/229229

And I hope there is some search (and replace) patterns also for any XIB properties.

Community
  • 1
  • 1
Lukasz
  • 19,816
  • 17
  • 83
  • 139
  • can u just search and replace in a folder with any old IDE? XIB files are just text after all. Obviously back everything up first. – Ben Clayton Sep 18 '12 at 12:03
  • But first I need to know what to search for. For example: if want to replace font properties and I search for UIFont (or NSFont), there are no xib files showing up in the results. Those must be stored in other form. But good advice - I will investigate them in text editor, but some documentation about xml representation of objects in XIB files would be useful. – Lukasz Sep 18 '12 at 12:09

1 Answers1

3

The .xib files are plain .xml files and can be simply edited.
Only non-default fonts are defined in .xib files. Simplified example:

<object class="NSTextField" id="298830314">
    <object class="NSTextFieldCell" key="NSCell" id="386648753">
        <object class="NSFont" key="NSSupport">
            <string key="NSName">Arial-BoldMT</string>
            <double key="NSSize">18</double>
            <int key="NSfFlags">16</int>
        </object>
    </object>
</object> 

In other words, remove all <object class="NSFont"> paths to revert to default fonts.
To change all NSTextField to specific fonts, add something like:

<object class="NSFont" key="NSSupport">
    <string key="NSName">Arial-BoldMT</string>
    <double key="NSSize">18</double>
    <int key="NSfFlags">16</int>
</object>

to all <object class="NSTextField">.

Xcode has no build-in feature to do this automatically in batch.

EDIT (Response to comment)

Choose specific fonts by clicking on the "Font Panel..." button:

Font Panel Button

Using the Font Panel you can select any font:

Font Panel

Anne
  • 26,765
  • 9
  • 65
  • 71
  • Good point about absence of the font description if there is default font set in XIB. Is this true to any other properties like color, autoresizing masks? Do you thing there is a change to use custom font names (after registering them in the Info.plist of course). I have noticed the is no way to set custom font using Interface builder interface. – Lukasz Sep 18 '12 at 16:19
  • @Lukasz - You can select any font using the font selector. Make sure the font is added to the system Font Book though, otherwise it won't show up. Checkout the code inserted into the `.xib` file and add the same in batch to the other `.xib` files. – Anne Sep 18 '12 at 23:13