ios 是否有用于 iPhone 开发的颜色选择器库/代码?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6448991/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 20:30:10  来源:igfitidea点击:

Is there a color picker library/code for iPhone development?

iphoneioscolorscolor-picker

提问by Greg

Is there an existing "color picker" library for iPhone development that I could leverage for my app?

是否有可以用于我的应用程序的 iPhone 开发的现有“颜色选择器”库?

采纳答案by Rahul Vyas

Yes there is an open source code for color picker you can use in your application. here is one http://www.fabiancanas.com/entry/iphone-color-picker

是的,您可以在应用程序中使用颜色选择器的开源代码。这是一个http://www.fabiancanas.com/entry/iphone-color-picker

回答by Καrτhικ

Here is a color-pickerwith the following features:

这是一个具有以下功能的颜色选择器

  • Shows a simple color pallete (simplifies the simple case), hue-grid or HSL selector.
  • iPhone 5 ready - color pallete expands to fill larger screen.
  • Hue grid - more variations of primary color. Color line in the bottom can be tapped to select color or grid can be swiped left and right.
  • HSL selector - for fine grain color selection, presents Hue circle and separate saturation and luminosity controls.
  • Alpha selector
  • Allows users to save their favorite colors. Favorites are stored in a file in the Documents directory.
  • Simple delegate model.
  • You can specify current color selection and title for header.
  • 显示一个简单的调色板(简化了简单的情况)、色调网格或 HSL 选择器。
  • iPhone 5 就绪 - 调色板扩展以填充更大的屏幕。
  • 色调网格 - 更多的原色变化。可以点击底部的颜色线来选择颜色或可以左右滑动网格。
  • HSL 选择器 - 用于细粒度颜色选择,呈现色相圆和单独的饱和度和亮度控制。
  • 阿尔法选择器
  • 允许用户保存他们喜欢的颜色。收藏夹存储在 Documents 目录中的文件中。
  • 简单的委托模型。
  • 您可以指定当前的颜色选择和标题的标题。

Screenshots: enter image description hereenter image description hereenter image description here

截图: 在此处输入图片说明在此处输入图片说明在此处输入图片说明

回答by Ethan Strider

I wrote a very simple one in Swift. It's probably not the best, but it looks nice and it's very simple.

我用 Swift 写了一个非常简单的。它可能不是最好的,但它看起来不错,而且非常简单。

https://github.com/EthanStrider/iOS-Projects/tree/master/ColorPickerExample

https://github.com/EthanStrider/iOS-Projects/tree/master/ColorPickerExample

Image Picker Screenshot

图像选择器截图

回答by Suragch

My full answer is here. If you don't want to use your own code rather than a third party library, you can do something like the following:

我的完整答案在这里。如果您不想使用自己的代码而不是第三方库,您可以执行以下操作:

Make your own color picker

制作自己的颜色选择器

Add a UIView, a UIImageView, and a UISliderto the storyboard.

将 a UIView、 aUIImageView和 a添加UISlider到故事板。

enter image description here

在此处输入图片说明

Use this image for the UIImageView:

将此图像用于 UIImageView:

enter image description here

在此处输入图片说明

Set the min and max values for the UISliderto 0.5 and 13.5.

将 的最小值和最大值设置UISlider为 0.5 和 13.5。

Hook up the UI elements to the View Controller and use the following code to convert the slider position to colors.

将 UI 元素连接到 View Controller 并使用以下代码将滑块位置转换为颜色。

class ViewController: UIViewController {

    // RRGGBB hex colors in the same order as the image
    let colorArray = [ 0x000000, 0xfe0000, 0xff7900, 0xffb900, 0xffde00, 0xfcff00, 0xd2ff00, 0x05c000, 0x00c0a7, 0x0600ff, 0x6700bf, 0x9500c0, 0xbf0199, 0xffffff ]

    @IBOutlet weak var selectedColorView: UIView!
    @IBOutlet weak var slider: UISlider!
    @IBAction func sliderChanged(sender: AnyObject) {
        selectedColorView.backgroundColor = uiColorFromHex(colorArray[Int(slider.value)])
    }

    func uiColorFromHex(rgbValue: Int) -> UIColor {

        let red =   CGFloat((rgbValue & 0xFF0000) >> 16) / 0xFF
        let green = CGFloat((rgbValue & 0x00FF00) >> 8) / 0xFF
        let blue =  CGFloat(rgbValue & 0x0000FF) / 0xFF
        let alpha = CGFloat(1.0)

        return UIColor(red: red, green: green, blue: blue, alpha: alpha)
    }
}

enter image description here

在此处输入图片说明

Or by positioning the slider on top of the image and setting the track tints to clear:

或者通过将滑块定位在图像顶部并将轨道色调设置为清除:

enter image description here

在此处输入图片说明

回答by Maksud Ali

Many color picker codes are available for iPhone development. You can use any according to your requirements. I suggest the following color picker, http://hayashi311.github.io/Color-Picker-for-iOS/

许多颜色选择器代码可用于 iPhone 开发。您可以根据自己的要求使用任何一种。我建议使用以下颜色选择器,http://hayashi311.github.io/Color-Picker-for-iOS/

回答by Dave

Here another articleI found which is easy to understand, you can customize this as you require, by simple changes.

这是我发现的另一篇易于理解的文章,您可以根据需要通过简单的更改对其进行自定义。

回答by Dave Robertson

Further to kabram's answer above, and answering PsychoDad's question, there is now a forkof the original Neovera Color Pickerwhich adds support for:

除了上面 kabram 的回答,并回答 PsychoDad 的问题,现在有一个原始Neovera Color Picker的分支,它增加了对以下内容的支持:

  • Landscape mode on iPhone
  • iPad (in a popover)
  • Animation when saving favorite colors
  • Uses UINavigationController to push views
  • iPhone 上的横向模式
  • iPad(在弹出窗口中)
  • 保存喜欢的颜色时的动画
  • 使用 UINavigationController 推送视图

回答by dB.

Here's another one, SHUColorPicker - https://github.com/sergdort/SHUColorPicker.

这是另一个, SHUColorPicker - https://github.com/sergdort/SHUColorPicker

回答by jjxtra

I thought I would throw my color picker into the ring. I use it in my app, You Doodleand I spent a couple weeks making it and testing it in the app. It contains a sample project to show you how to get started with it and is open sourced under the MIT license. It supports any device (iOS 6+), any resolution and portrait and landscape. Favorites, recents, color by hue, color wheel and importing textures, as well as deleting and moving favorites to the front is supported.

我想我会把我的颜色选择器扔进戒指。我在我的应用程序You Doodle 中使用它,我花了几个星期制作它并在应用程序中测试它。它包含一个示例项目,向您展示如何开始使用它,并且在 MIT 许可下开源。它支持任何设备(iOS 6+)、任何分辨率以及纵向和横向。支持收藏夹、最近收藏、按色调着色、色轮和导入纹理,以及删除收藏夹并将其移到前面。

I've tried to combine the good pieces of all the other color pickers and ensure that the MIT license allows a no hassle integration into any project.

我试图结合所有其他颜色选择器的优点,并确保 MIT 许可证允许轻松集成到任何项目中。

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

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

Screenshots:

截图:

DRColorPicker iPhoneDRColorPicker iPadDRColorPicker iPhoneDRColorPicker iPadDRColorPicker iPhoneDRColorPicker iPad

DRColorPicker iPhoneDRColorPicker iPadDRColorPicker iPhoneDRColorPicker iPadDRColorPicker iPhoneDRColorPicker iPad