MegaManX
MegaManX

Reputation: 8918

iPhone Can subview be transparent?

I have main view and i added subview to it. I set subview's background to be semi transparent, but subview is drawn in solid color. I even tried setting opaque to NO.

detailsView.opaque = NO;
detailsView.backgroundColor = UIColorMakeRGBA(0, 0, 100, 100);

I can make the vsubview to be transparent via alpha property (but all things on subview will also be transparent), but i really want just to set background color to be semi transparent.

Upvotes: 0

Views: 168

Answers (3)

sch
sch

Reputation: 27506

I assume UIColorMakeRGBA is a function that you have implemented. In that case, I am sure, it looks like this:

#define UIColorMakeRGBA(redValue, greenValue, blueValue, alphaValue) [UIColor colorWithRed:(redValue)/255.0f green:(greenValue)/255.0f blue:(blueValue)/255.0f alpha:(alphaValue)]

Notice that alpha is not divided by 255.0, so you should use a value between 0.0 and 1.0 for that parameter and not 100. If you use 100, you will end up with a color with alpha equal to 1.0.

detailsView.backgroundColor = UIColorMakeRGBA(0, 0, 100, 0.5f);

Upvotes: 1

beryllium
beryllium

Reputation: 29767

Set alpha to desired value in colorWithRed:green:blue:alpha method

detailsView.backgroundColor = [UIColor colorWithRed:0/255.0f 
                                              green:30/255.0f 
                                               blue:160/255.0f 
                                              alpha:0.5f];

Upvotes: 2

wattson12
wattson12

Reputation: 11174

I don't know the UIColorMakeRGBA function, but it looks to me like you are creating a completely blue colour with alpha of 1, so it should not be transparent. Try setting the background colour line to be

detailsView.backgroundColor = UIColorMakeRGBA(0, 0, 100, 50);

Alternatively just use [[UIColor blueColor] colorWithAlphaComponent:0.5f];

Upvotes: 1

Related Questions