【发布时间】:2012-05-16 02:21:39
【问题描述】:
我想制作一个类似于您在此处第一个单元格右侧看到的效果:
我猜它是某种带有渐变的叠加视图,但我只是不知道它是如何配置透明度的。我尝试使用渐变制作自己的叠加视图并将颜色的 alpha 设置为向下,但它只是显示为灰白色渐变。
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = UIGraphicsGetCurrentContext();
UIColor *gradBegin = [UIColor colorWithWhite:1.0 alpha:0.8];
UIColor *gradEnd = [UIColor colorWithWhite:1.0 alpha:0.6];
NSArray* gradientColors = [NSArray arrayWithObjects:
(id)gradBegin.CGColor,
(id)gradEnd.CGColor, nil];
CGFloat gradientLocations[] = {0, 1};
CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef)gradientColors, gradientLocations);
CGContextDrawLinearGradient(context, gradient, CGPointMake(rect.origin.x, rect.origin.y + rect.size.height/2.0),
CGPointMake(rect.origin.x + rect.size.width, rect.origin.y + rect.size.height/2.0), 0);
此屏幕截图中究竟发生了什么,我该如何复制它?
【问题讨论】:
-
不就是一个 UIImageView,在单元格的内容视图之上有一个从 clearColor 到灰色的渐变吗?
-
将 uiimageview 放在其他视图之上,并使用具有从白色到透明渐变的 png。
-
我可以在没有 UIImageView 的情况下执行此操作,而只使用带有 CoreGraphics 的 UIView 吗?
-
你是如何在上面制作覆盖视图的,它的背景颜色是什么?
-
它只是一个带有浅灰色到深灰色渐变的正方形......真的没有透明度
标签: iphone objective-c ios core-graphics