swift - Xcode Swift 编辑器中的这个颜色功能是什么?

标签 swift xcode color-picker

当我在类声明自动完成 block 的类名占位符中输入 Color 时,弹出了一个颜色选择器。它允许我在源代码中直接放置一个彩色小方 block 。

我试图用谷歌搜索它,但找不到任何合适的结果,所以我想问一下这个功能的用途以及如何在源代码中使用这些方 block 。它们可以用作标识吗?作为类名?你能设置例如的值吗? SKColors 使用这些方 block ?怎么回事?

enter image description here

使用 Xcode 8.2.1

最佳答案

这是“颜色文字”功能。它类似于 Image literals, described elsewhere on Stack Overflow .

您基本上得到一个颜色选择器并选择一种颜色,该颜色将在一个小方 block 中预览。

引用自Apple :

Literals are the actual values of your data represented in their native format, directly within the Xcode editor. For instance, there’s no need to type “myImage.jpg” in the editor – just drag your image from the Finder and the actual image will appear in-line with your code. Instead of showing RGB values to indicate color, the playground will render a color swatch. Literals in playgrounds behave similarly to code you would otherwise hand-author in regular Swift code, but are rendered in a much more useful manner.

关于swift - Xcode Swift 编辑器中的这个颜色功能是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44605150/

相关文章:

ios - 如何将标识符添加到自动布局 anchor 约束?

ios - 在 Swift 中裁剪 UIImage 的问题

ios - 字典在展开可选值时意外发现 nil

swift - 如何在swiftUI中使用分页选项卡 View 时阻止页面上下滚动

objective-c - 如何在细节 Controller 中引用属性列表?

xcode - 该 bundle 无效。 Apple 目前不接受使用此版本操作系统构建的应用程序。 (优胜美地)

visual-studio - 十六进制中的所有 Microsoft 标准颜色

ios - 为屏幕尺寸调整 Collection View 单元格

wpf - SelectedColor 绑定(bind)不会从 ColorPicker 更新到 Model

opengl - 在 OpenGL 中使用 AntiAliasing 进行颜色选择?