Color wheel or color picker in iOS

前端 未结 8 653
故里飘歌
故里飘歌 2020-12-31 10:12

How can I make a color wheel, color picker, or hue selector in iOS for use on the iPad.

Here is an example picture of a color picker similar to what I want.

8条回答
  •  醉话见心
    2020-12-31 10:34

    I did create a sector of a color wheel in draw(_ rect: CGRect). See here.

    That my color wheel:

    This view based on the next lines of code:

    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))
            }
        }
    }
    

提交回复
热议问题