سؤال

Here's an interesting problem for you:

We are in the process of re-skinning our entire app, which consists of over 100,000 lines of code and almost 100 XIB files. The new design requires (almost) every label in the app to use a new custom font, whereas the old app uses the default font of Helvetica Neue.

What is the most efficient way of changing as many of the UILabels as possible? We don't want to have to manually change thousands of labels both in code and in XIBs (which is especially difficult because we are using a non-system font).

We've discussed swizzling UILabel's creation methods to default to using the new custom font, which would still allow for the few labels that would remain in Helvetica Neue to be customized after creation.

Thoughts?

هل كانت مفيدة؟

المحلول

Take a look at NUI https://github.com/tombenner/nui. You can customize a lot controls with it using a CSS-like stylesheet and implement it via subclasses or categories.

نصائح أخرى

You should probably subclass UILabel and override either an initmethod of your choice, or awakeFromNib, and set the custom font there. Then you can go through the xib, either manually, or open it up in a text-editor and add a line like

<string key="X.CustomClassName">YourCustomLabelClass</string>

To set the specified label to your custom label class.

Swizzling is a good option . If you want to do it other way and have problems with custom fonts, I usually make a trivial subclass of UILabel that changes it's font in awakeFromNib for each custom font so I can lay them out in the interface builder.

But... This comes to my mind: [[UILabel appearance] setFont:xxx];

I am not sure how you would deal with keeping the size, though. Perhaps swizzle is the best choice

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top