ios - Swift - 创建自定义颜色数组
问题描述
有没有办法创建一组自定义颜色?我知道我可以创建自定义颜色,class UIColors
但就我而言,我需要一组自定义颜色。
我想实现这样的目标:
let listColors: [UIColor] = [
let color1 = UIColor(displayP3Red: 1, green: 1, blue: 1, alpha: 1),
let color2 = UIColor(displayP3Red: 2, green: 2, blue: 2, alpha: 1),
let color3 = UIColor(displayP3Red: 3, green: 3, blue: 3, alpha: 1),
]
解决方案
或者,如果您希望能够按名称或数组索引引用它们:
let color1 = UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0), //White
let color2 = UIColor(red: 0.5, green: 0.5, blue: 0.5, alpha: 1.0), //Gray
let color3 = UIColor(red: 1.0, green: 0.0, blue: 0.0, alpha: 1.0), //Red
let listColors: [UIColor] = [color1, color2, color3]
推荐阅读
- c# - Outlook ItemAdd 事件未一致触发
- python - 如何在不使用 Dataflow 且不使用 Python 中的 ACK 的情况下排除 Pubsub 中的重复消息?
- python - 使用 PyCharm 远程解释器以另一个用户身份运行
- terraform - Terraform 转义 bash 命令替换
- java - 如何通过javascript将所有div并排放置在宽度为50的父div中?
- 2sxc - 使用 2sxc 模块的图像管理器时出现内容解码错误
- d - 用 DMD 编译 D 项目
- python - 如何为两个相关模型创建输入表单
- javascript - CSS - 带有图像推子的绝对和相对位置
- android - 如何更改firebase数据的值,它databaseRef与不同类中的valueEventListener存在