使用UIGraphics设置在UIImage上绘制的项目的可见性

时间:2013-06-26 08:35:33

标签: ios objective-c uiimage uigraphicscontext

我有一个UIImage * backgroundImage = [[UIImage alloc] initWithData:imgData];

我将使用以下方法在此图像上绘制图像:

CGSize finalSize = [backgroundImage size];
UIImage *newImage; UIGraphicsBeginImageContext(finalSize);
newImage = backgroundImage;
[newImage drawInRect:CGRectMake(0,0,finalSize.width,finalSize.height)];
UIImage *imageItem = [[UIImage alloc] initWithData:itemImgData];
[imageItem drawInRect:CGRectMake(10,10,100,100)];
newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

有没有什么方法可以引用在backgroundImage上绘制的imageItem,这样我可以设置它的可见性,在绘制imageItem后可见/不可见?假设对imageItem的引用是imageItemRef,我想根据特定条件设置它的可见性:

if(shouldVisible){
 [imageItemRef setHidden:TRUE];
else
 [imageItemRef setHidden:FALSE];

我没有使用另一个视图来表示backgroundImage之上的项目的原因是因为我正在对backgroundImage进行缩放,并且我希望在backgroundImage缩放时也可以缩放项目。

1 个答案:

答案 0 :(得分:0)

您可以使用以下方法设置上下文中用于绘图操作的Alpha:

CGContextSetAlpha(UIGraphicsGetCurrentContext(), 0.5);
相关问题