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

三世轮回 提交于 2019-11-29 23:07:49

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]

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!