Using the drawrect function of a UIView for this purpose would be horrendously slow. Any time you animate the view, move it, move something else on top of it or whatever it would have to be redrawn (slow process). UIImageView is optimized for this task and it would be beneficial to use it.
But if you are dead set on drawrect then you would have to create "pixel" rectangles by taking the width and height of your UIView divided by the width and height of your image (in pixels). Then iterate through every pixel row and column and use the CGContextSetFillColor
and CGContextFillRect
. It would probably make performance sense to sort the array of colors into like colors and draw the same color all at once. But still much slower than UIImageView. The memory overlap of having your array and a UIImageView is not bad enough to outweigh the beneifits.