Divine Propotion
Divine Propotion

Reputation: 172

Adding a UIView as a subview to UIImageView

I am working on creating a color picker for "iOS". I am using this project, since it does what i want: "This"

I want to create a moveable circle (UIView) on top of the palette (UIImageView).

What I want to do is, while users move the circle, take the touch point and call the method getPixelColorAtLocation(); and change the background color of the circle to the color on current point. (Seen on most of the color palette/wheels)

The method getPixelColorAtLocation() is available on a child view. I created a circle with UIView on parent view, the problem is I cant call to getPixelColorAtLocation() from parent view.

My question is, Is there anyway to add a UIView as a subView to UIImageView. If I cant, what choices do I have to achieve what I want?

Upvotes: 1

Views: 632

Answers (2)

ColdLogic
ColdLogic

Reputation: 7265

Yes you can do this.

[myImageView addSubview:sampleView];

Upvotes: 1

futurevilla216
futurevilla216

Reputation: 992

An image view is just a subclass of UIView, so you can add subviews to it however you'd like. If there's a reason why you can't do so, then you can always make it a subview of the image view's superview, move it to the front, and then use convertPoint:toView: to convert to the image view's coordinate system, then get the pixel color.

Upvotes: 0

Related Questions