簡體   English   中英

iOS 中的色輪或顏色選擇器

[英]Color wheel or color picker in iOS

如何在 iOS 中制作色輪、顏色選擇器或色調選擇器以在 iPad 上使用。

這是類似於我想要的顏色選擇器的示例圖片。

在此處輸入圖片說明

@All 提前致謝。

這篇文章可以幫到你。 選擇顏色的一種簡單方法是獲取您提供的圖像中像素的顏色。 這個 github 項目也有一個顏色選擇器的完整源代碼。

我的顏色選擇器,易於集成https://github.com/sakrist/VBColorPicker在此處輸入圖片說明

其他答案沒有錯。 我只是分享另一個使用 Swift 創建的顏色選擇器

快速色輪

我知道這個問題已經得到了回答和接受,但是這里提到的所有 github 項目看起來都已經過時了。 我發現RSColorPicker易於使用並且具有我正在尋找的所有功能。 最重要的是它並沒有過時。

我想我會把我的顏色選擇器扔進戒指。 我在我的應用程序You Doodle 中使用它,我花了幾個星期制作它並在應用程序中測試它。 它包含一個示例項目,向您展示如何開始使用它,並且在 MIT 許可下開源。 它支持任何設備(iOS 6+)、任何分辨率以及縱向和橫向。 支持收藏夾、最近收藏、按色調着色色輪和導入紋理,以及刪除收藏夾並將其移到前面。

我試圖結合所有其他顏色選擇器的優點,並確保 MIT 許可證允許輕松集成到任何項目中。

Github: https : //github.com/jjxtra/DRColorPicker

截圖:

DRColorPicker iPhoneDRColorPicker iPadDRColorPicker iPhoneDRColorPicker iPadDRColorPicker iPhoneDRColorPicker iPad

在這里找到了另一篇非常簡單的文章...,其中包含示例代碼。

我確實在 draw(_rect: CGRect) 中創建了一個色輪的扇區。 看這里。

那我的色輪: 色輪扇區

此視圖基於以下代碼行:

override func draw(_ rect: CGRect) {
    guard let context = UIGraphicsGetCurrentContext() else {
        return
    }

    // Choice width and x position of a rect where will be placed you picker
    for x in stride(from: bounds.midX - bounds.height, to: bounds.midX + bounds.height, by: elementSize) {

        // Choice height and y position of the rect
        for y in stride(from: 0, to: rect.height, by: elementSize) {

            // Select color for a point
            context.setFillColor(colorFor(x: x, y: y))

            // Select color for the point with elementSize which we declare and init as class property
            context.fill(CGRect(x: x, y: y, width: elementSize, height: elementSize))
        }
    }
}

如果您將應用程序定位到iOS 14 ,則不需要第 3 方代碼。 它有UIColorPickerViewController並且非常簡單。

let picker = UIColorPickerViewController()
picker.delegate = self
present(picker, animated: true, completion: nil)

您可以設置初始 selectedColor,或將 supportsAlpha 更改為 false 以隱藏 alpha 滑塊並僅允許不透明顏色

UIColorPickerViewController

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM