How can I make an “appearance file” for NSAppearance?

后端 未结 2 1613
生来不讨喜
生来不讨喜 2020-12-24 08:02

I was reading the Cocoa documentation and stumbled across some new features in the 10.9 API.

From the docs I gather that the NSAppearance class and a re

相关标签:
2条回答
  • 2020-12-24 08:17

    There is a private framework called "CoreThemeDefinition" which handles uicatalog files, these files can be turned into ".car" files and loaded using NSAppearance. I personally think Apple is going to include an editor in Xcode in the future, but for now you can use this little tool I've made: https://github.com/insidegui/AppearanceMaker

    You first open the app and select a place to save the uicatalog file, then you click "create skeleton". This will export various PSDs containing the default images for the controls, you can then edit them, save and export the car file using the app.

    This file needs to be included in your app's resources, and you load this custom appearance using:

    [[NSAppearance alloc] initWithAppearanceNamed:@"Your-appearance-name" bundle:nil]
    
    0 讨论(0)
  • 2020-12-24 08:33

    EDIT: Guilherme's response is more accurate, although there is still no public way of altering appearances like you can in iOS.

    NSAppearance isn't much like UIAppearance (from what I can tell), it only relates to having controls under normal or light colored appearances. An example of this would be when you draw into a popover (light) vs a window toolbar perhaps (normal), NSAppearance allows you to identify which environment you're drawing into. To be honest I haven't used it yet, but the most information I've found was in the WWDC 2013 video on What's new in Cocoa and the 10.9 release notes

    From my understanding, it allows you to specify what the control looks like on a particular background. If a control you use is to be reused on a different background, you could check the current appearance and draw your control accordingly using [NSAppearance currentAppearance]

    Another important part is that there is a new protocol your views or windows can adopt called the NSAppearanceCustomization protocol which allows you to specify that view's appearance. Not exactly sure how this works but it's there. Some Cocoa control also have these implemented which are discussed in the HIG for Controls.

    There are 2 appearances that Apple defines but you might be able to define your own using your own strings (again, not sure). At the bottom of the docs you linked to you'll find these 2 constants:

    APPKIT_EXTERN NSString *const NSAppearanceNameAqua;
    APPKIT_EXTERN NSString *const NSAppearanceNameLightContent;
    

    So it's no UIAppearance, it's just a way of knowing what type of background you're drawing onto.

    0 讨论(0)
提交回复
热议问题