我们如何使用资产目录颜色集? [英] How can we use Assets Catalog Color Sets?

查看:101
本文介绍了我们如何使用资产目录颜色集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通常在iOS上使用自定义UIColors,并使用Swift扩展,但是现在使用iOS 11/Xcode 9,我们可以创建颜色集.我们如何使用它们?

I usually use custom UIColors on iOS using extensions with Swift, but now with iOS 11/ Xcode 9 we can create Colors Sets. How can we use them?

更新-提示

正如@Cœur所说,我们可以拖放颜色,并像UIColor对象一样使用它,并且可能的解决方案是将其用作扩展:

As @Cœur says we can drag&drop de color, and use it like a UIColor object and a possible solution could be use it as a extension:

或作为常量:

现在,我想知道是否可以像对资产图像的UIImage访问一样访问它们,例如:

Now I wanna know if we can access them like an UIImage access to an Asset Image or not, like:

UIImage(named: "image-name") -> UIColor(named: "color-name")

推荐答案

UIColor(named: "myColor") 

来源: WWDC 2017会议237-MapKit中的新增功能

注意事项:您项目的部署目标必须设置为iOS 11.0.

Caveat: Your project's Deployment Target needs to be set to iOS 11.0.

这篇关于我们如何使用资产目录颜色集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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