2013-03-23 141 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];