简体   繁体   English

iPhone应用程序中UIView中具有透明部分的背景图片

[英]Background image with transparent portion in UIView in iPhone application

Actually i am displaying events in calendar and for that i am adding subviews for events in UIScrollview. 实际上,我在日历中显示事件,为此我在UIScrollview中添加事件的子视图。 now i want to make some portion transparent in my particular event. 现在我想在我的特定事件中使某些部分透明。 Please check below image. 请检查下图。

在此处输入图片说明

so i want to make that background image of event transparent with particular frame. 所以我想使事件的背景图像与特定框架透明。 Let me know if you have any idea about this or any alternative for that. 让我知道您是否对此有任何想法或任何其他选择。

Here is a basic solution to clear a frame in a view using a custom drawLayer:inContext: method for your eventView custom class (the class that draws your event). 这是使用eventView自定义类(绘制事件的类)的自定义drawLayer:inContext:方法清除视图中框架的基本解决方案。 Of course you have to inherit a class from UIView before (eg. MyEventViewClass). 当然,您必须先从UIView继承一个类(例如MyEventViewClass)。 You also have to set the opaque property to NO 您还必须将opaque属性设置为NO

-(void)drawLayer:(CALayer*)layer inContext:(CGContextRef)context
{
       // Fill the bg with the color you want (here it is gray)
       // You can also draw an image (CGContextDrawImage:)
    CGContextSetFillColorWithColor(context, [UIColor grayColor].CGColor);
    CGContextFillRect(context, self.bounds);

      // Then clear the frame
    CGContextSetBlendMode(context, kCGBlendModeClear);
    CGContextFillRect(context, frameToClear);
}

Is it clear ? 清楚吗 ? ;) ;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM