核心图形透明叠加

时间:2013-03-23 19:19:30

标签: iphone ios objective-c xcode core-graphics

我正在使用我自己的自定义子类UITableViewCell替换UIView的背景视图,其中我用自己的方法覆盖drawRect方法,这会创建一个多色的和改变背景。

问题在于,当选择TableViewCell时,下面的图形完全隐藏,看起来很奇怪。我需要创建自定义selectedBackgroundView才能解决此问题。问题是该视图需要在已存在的图形上创建蓝色渐变色调,并且我不知道如何绘制CGRect或类似的部分透明的东西。

1 个答案:

答案 0 :(得分:2)

// Write this In your - (void)drawRect:(CGRect)rect
// To draw semi transparent Square
// Create Current Context To Draw
CGContextRef context = UIGraphicsGetCurrentContext();

UIBezierPath *square = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 100, 100)];
// following method will fill red color with alpha 0.4 last one in parameter list
// first 3 are Red, Green and Blue Respectively.
CGContextSetRGBFillColor(context, 1, 0, 0, 0.4);
[square fill];
[square stroke];