【问题标题】:Background image with transparent portion in UIView in iPhone applicationiPhone应用程序中UIView中具有透明部分的背景图像
【发布时间】:2012-02-13 00:58:48
【问题描述】:

实际上,我正在日历中显示事件,为此我正在为 UIScrollview 中的事件添加子视图。现在我想在我的特定活动中使某些部分透明。请检查下图。

所以我想用特定的框架使事件的背景图像透明。如果您对此或任何替代方案有任何想法,请告诉我。

【问题讨论】:

  • 你的背景是简单的颜色还是需要图片?'(

标签: iphone objective-c calendar transparent


【解决方案1】:

这是一个基本的解决方案,可以使用您的 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);
}

清楚吗? ;)

【讨论】:

    猜你喜欢
    • 2021-12-30
    • 1970-01-01
    • 1970-01-01
    • 2023-03-22
    • 2012-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多