【发布时间】:2012-02-13 00:58:48
【问题描述】:
实际上,我正在日历中显示事件,为此我正在为 UIScrollview 中的事件添加子视图。现在我想在我的特定活动中使某些部分透明。请检查下图。
所以我想用特定的框架使事件的背景图像透明。如果您对此或任何替代方案有任何想法,请告诉我。
【问题讨论】:
-
你的背景是简单的颜色还是需要图片?'(
标签: iphone objective-c calendar transparent
实际上,我正在日历中显示事件,为此我正在为 UIScrollview 中的事件添加子视图。现在我想在我的特定活动中使某些部分透明。请检查下图。
所以我想用特定的框架使事件的背景图像透明。如果您对此或任何替代方案有任何想法,请告诉我。
【问题讨论】:
标签: iphone objective-c calendar transparent
这是一个基本的解决方案,可以使用您的 eventView 自定义类(绘制事件的类)的自定义 drawLayer:inContext: 方法来清除视图中的框架。当然,您必须先从 UIView 继承一个类(例如 MyEventViewClass)。
您还必须将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);
}
清楚吗? ;)
【讨论】: