如何做一个“外观文件”为NSAppearance? [英] How can I make an "appearance file" for NSAppearance?

查看:743
本文介绍了如何做一个“外观文件”为NSAppearance?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在阅读Cocoa文档,并在10.9 API中遇到了一些新功能。

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

从文档,我认为 NSAppearance 类和相关协议 NSAppearanceCustomization 看起来是一种定制 NSView 及其后代的外观的方法。

From the docs I gather that the NSAppearance class and a related protocol NSAppearanceCustomization Appear to be a means of customizing the appearance of NSView and its descendants.


NSAppearance对象表示一个文件,该文件指定应用于应用程序中一部分UI元素的标准或自定义外观。应用程序可以包含多个外观文件,因为NSAppearance符合NSCoding,您可以使用Interface Builder将UI元素分配给外观。

通常,您可以通过使用Xcode创建一个窗口包含您要自定义的视图和应应用于其的自定义图片的外观文件。 Xcode将文件的艺术内容转换为AppKit在显示指定视图时可以绘制的运行时格式。

An NSAppearance object represents a file that specifies a standard or custom appearance that applies to a subset of UI elements in an app. An app can contain multiple appearance files and—because NSAppearance conforms to NSCoding—you can use Interface Builder to assign UI elements to an appearance.
Typically, you customize a window by using Xcode to create an appearance file that contains the views you want to customize and the custom art that should be applied to them. Xcode transforms the file’s art content into a runtime format that AppKit can draw when the specified views are displayed.

有前途,但在文档中无处可以找到一个外观文件是什么或如何使一个。

Well that all sounds neat and promising, but nowhere in the documentation can I find what an appearance file is or how to make one. Google searches are coming up empty other than for the thin documentation I have already read.

我发现UIKit有一个类似的声音 UIAppearance

I do see that UIKit has a similar sounding UIAppearance class, but from what I can tell this is not a straight port of the UIKit class.

有人知道如何制作这些魔术外观文件之一,以及我们可以用它们做什么?

Does anybody know how to make one of these magic "appearance files" and what exactly we can do with them?

推荐答案

>有一个名为CoreThemeDefinition的专用框架,用于处理uicatalog文件,这些文件可以转换为.car文件并使用NSAppearance加载。我个人认为苹果将来会在Xcode中包含一个编辑器,但现在你可以使用我做的这个小工具: https://github.com/insidegui/AppearanceMaker

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

您首先打开应用程序并选择一个地方保存uicatalog文件,然后点击创建骨架。这将导出包含控件默认图像的各种PSD,然后可以使用应用程序编辑它们,保存并导出汽车文件。

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]

这篇关于如何做一个“外观文件”为NSAppearance?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆