2013-03-23 105 views
0

我用我自己的自定义子类UIView替换了UITableViewCell的背景视图,其中我用我自己的方法覆盖了drawRect方法,该方法创建了多色和变化的背景。核心图形透明覆盖

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

回答

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];