SwiftColorWheel

Carthage compatible Swift Package Manager compatible

一个美观、可定制的 Swift iOS 颜色选择器。

ScreenshotRotating ScreenshotScreenshot

更多相关的 iOS 控件

您可能还会对以下使用 Swift 编写的 iOS 控件感兴趣:

另请 在 CocoaControls 上查看

如果您真的喜欢这个库(即赞助)

我做这一切都是为了乐趣和喜悦,而且我坚信开源的力量。尽管如此,如果使用我的库给您带来了快乐,并且您想说声“谢谢”,如果您通过赞助按钮之一支持我,我会像一个 4 岁的孩子得到一个巨大的冰淇淋甜筒一样微笑☺️💕

如果您想向其他人发送一个可爱的感谢,也许可以查看我的 iOS 应用 💌 SoundCard,向他们发送带有个人音频信息的真实明信片。

Buy Me A Coffee

安装

Swift Package Manager

只需添加 https://github.com/dmrschmidt/SwiftColorWheel 并选择 "Up to Next Major"(直到下一个主版本)

Carthage

只需将以下内容添加到您的 Cartfile 并运行 carthage update

github "dmrschmidt/SwiftColorWheel", ~> 1.5

使用方法

您可以将 ColorWheelRotatingColorWheel 作为自定义 UIView 子类添加到您的界面构建器中。或者,您当然可以简单地以编程方式将其作为子视图添加到任何普通的 UIView 中。

这将渲染您的颜色选择器。但是它尚未响应您的点击。为此,将自己设置为它的 delegate(委托)。 请参阅下面非常简化的代码示例

class MyViewController: UIViewController, ColorWheelDelegate {
    private var colorWheel: ColorWheel!

    override func viewDidLoad() {
        super.viewDidLoad()

        colorWheel = ColorWheel(frame: view.frame)
        colorWheel.delegate = self
        view.addSubview(colorWheel)
    }

    // MARK: - ColorWheelDelegate

    func didSelect(color: UIColor) {
        view.backgroundColor = color
    }
}

定制

您可以通过各种公开的属性来修改颜色选择器的外观。

// Extra padding in points to the view border.
colorWheel.padding = 13.0

// Radius in point of the central color circle (for black & white shades).
colorWheel.centerRadius = 5.0

// Smallest circle radius in point.
colorWheel.minCircleRadius = 1.0

// Largest circle radius in point.
colorWheel.maxCircleRadius = 5.0

// Padding between circles in point.
colorWheel.innerPadding = 3

/**
 Degree by which each row of circles is shifted.
 A value of 0 results in a straight layout of the inner circles.
 A value other than 0 results in a slightly shifted, fractal-ish / flower-ish look.
*/
colorWheel.shiftDegree = 0

// Overall density of inner circles.
colorWheel.density = 1.0

// Stroke color highlighting currently selected color. Set nil to disable highlighting.
// Default is UIColor.white.
colorWheel.highlightStrokeColor = nil

在某些情况下(例如当 RotatingColorWheel 放置在 UIScrollView 中时),您可能需要调整旋转的默认手势处理。 如果这样做,您可以访问原始手势处理程序并在组合中使用它。

let originalHandler = rotatingWheel.panRecognizer.delegate
yourRetainedHandler = YourTweakedHandler(complementing: originalHandler)
rotatingWheel.panRecognizer.delegate = yourRetainedHandler
rotatingWheel.rotateRecognizer.delegate = yourRetainedHandler

YourTweakedHandler 可以结合原始提供的处理程序来实现 gestureRecognizerShouldBegin(_:)

实际体验

SoundCard - 带有声音的明信片 让您可以发送带有音频信息的真实物理明信片。直接从您的 iOS 设备发送。

SwiftColorWheel 用于为 SoundCard - 带有音频的明信片 发送的明信片上,由音频信息衍生的波形着色。

 

Download SoundCard

在 App Store 上下载 SoundCard。

 

Screenshot