Has anyone seen the problem of [UIColor initWithPatternImage] ignoring PNG alpha values? If so, what is the best fix?
I use png as the background layer for my array of button objects, and it contains several predefined alpha per pixel values โโin the image, which should be used as the background texture. It loads as a template / texture color, but the entire transparent area is transparent as an opaque black.
It is important that I get the correct alpha values โโso that the button images are displayed correctly. Button frames do not include alpha shadows from the background, as this is not a โclickable" part of the button. In addition, my images of object objects and background images also use transparency, so in fact you need to have a clear background immediately behind each button to ensure the correct current current color settings (the bottom layer of the UIView will have its own background color set to the current color selected by the user ) Setting only one alpha value for a UIView layer containing this texture is also not suitable for my needs.
Any help would be greatly appreciated. My current workaround would be to use a fully bloated, repeatedly programmed layout of multiple UIImageViews using png instead of a single UIView with pattern filling.
Here is a snippet of code, but it is pretty standard for turning UIImage into UIColor for use as template / texture color:
UIView *selectorView = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,320)];
UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"SelectorViewBackground.png"]];
selectorView.backgroundColor = background;
[mainView addSubview:selectorView];
[self addSubview:mainView];
[selectorView release];
[background release];
source
share