I need a UIImageView that can draw itself in color or b/w according to a flag:
BOOL isGrey;
I\'m trying to do it by drawing a black rectangle
You could try to add a mask to the view's Core Animation layer.
CALayer *maskLayer = [CALayer layer];
[maskLayer setBounds:CGRectMake(0.0f, 0.0f, 100.0f, 100.0f)];
// Center the layer
[maskLayer setPosition:CGPointMake([self view].bounds.size.width/2,
[self view].bounds.size.height/2)];
// Set the cornerRadius to half the width/height to get a circle.
[maskLayer setCornerRadius:50.f];
[maskLayer setMasksToBounds:YES];
// Any solid color will do. Just using black here.
[maskLayer setBackgroundColor:[[UIColor blackColor] CGColor]];
// Set the mask which will only allow that which is in the
// circle show through
[[[self view] layer] setMask:maskLayer];
One other thought. Why can't you just create a b&w version of the image and swap that out depending on your flag?