Search code examples
objective-ciosuiviewcontrollerstatic-librariesuiappearance

UIAppearance in Static Library


We provide our clients with a static library that allows them to display our viewcontrollers. We use UIAppearance to set the style of our UIViewControllers.

However, using UIAppearance customizes the appearance for those who use the static library as well but we want it to only apply it to our static library.

Is there a way to make UIAppearance on the library level?

Thanks in advance!


Solution

  • You need to use the method as [[UINavigationBar appearanceWhenContainedIn:(Class <UIAppearanceContainer>)ContainerClass,...] setProperty:]

    For example,

    [[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil]
           setTintColor:myNavBarColor]
    

    containedIn part accepts, something like [UIPopoverController class] etc.. So you might have to subclass all UI controllers and provide it as [CustomController class] in appearanceWhenContainedIn method. For more details on appearanceWhenContainedIn method, check apple documentation here.