3 Star 0 Fork 1

Gitee 极速下载/RandomColorSwift

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/onevcat/RandomColorSwift
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Random Color Swift

Inspired by David Merfield's randomColor.js. It is a ported version to Swift. You can use the library to generate attractive random colors on iOS or macOS.

Install

This framework supports Swift 4.0/4.2/5.0 and above.

Swift Package Manager

Just like using any other Swift Package, add this repo to the dependencies section and depend it in your target:

let package = Package(
    name: "MyApp",
    //...
    dependencies: [
        .package(url: "https://github.com/onevcat/RandomColorSwift.git", .upToNextMajor(from: "2.0.0")),
    ],
    targets: [
        .target(
            name: "MyApp",
            dependencies: ["RandomColor"]),
    ]

Or, use the Swift Package Manager integrated in Xcode 11 or above to add this package as a dependency to your app.

CocoaPods

The easiest way to use RandomColor is installing it by CocoaPods. Add these lines to your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
# platform :osx, '10.10'
use_frameworks!

pod 'RandomColorSwift'

Carthage

Carthage is also supported:

github "onevcat/RandomColorSwift"

Manually

If you need to support iOS 7.x, you will need to add the library manually into your project since dynamic framework is not supported for iOS 7.

Clone this repo and throw the source files under RandomColor folder into your project to use it.

Example

import RandomColor

// Returns a UIColor or NSColor object for an attractive color
let color = randomColor()

// Returns an array of ten green colors
let greenColors = randomColors(count: 10, hue: .green)

// Returns a color for light blue
let lightBlurColor = randomColor(hue: .blue, luminosity: .light)

// Returns a color for a 'truly random' color
let randomColor = randomColor(hue: .random, luminosity: .random)

// Returns an array of ten dark pink colors
let darkPinkColors = randomColors(count: 10, hue: .pink, luminosity: .dark)

// Returns an array of twenty colors at hue of 120
let colors = randomColors(count: 20, hue: .value(120), luminosity: .random)

There is also a demo project in this repo.

Options

You can pass an options object to influence the type of color it produces. The options object accepts the following properties:

Hue – Controls the hue of the generated color. Possible hue values for colors are .monochrome, .red, .orange, .yellow, .green, .blue, .purple, .pink, .random or .value(Int). If you use .value(Int), you should pass an Int between 0 and 360.

Luminosity – Controls the luminosity of the generated color. You can pass .bright, .light, .dark or .random.

Count – An Int which specifies the number of colors to generate.

Acknowledgements

Thanks for David Merfield bringing us randomColor.js, which is a great utility.

The demo project is using Chirag Mehta's Name the Color JavaScript library to extract name of color.

License

This project is licensed under the terms of the MIT license.

Copyright (c) 2015 Wei Wang (http://onevcat.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

RandomColorSwift 是从 randomColor.js 移植过来的 Swift 颜色生成器,非常迷人 展开 收起
README
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Swift
1
https://gitee.com/mirrors/RandomColorSwift.git
git@gitee.com:mirrors/RandomColorSwift.git
mirrors
RandomColorSwift
RandomColorSwift
master

搜索帮助