我正在使用我自己的自定义子类UITableViewCell
替换UIView
的背景视图,其中我用自己的方法覆盖drawRect
方法,这会创建一个多色的和改变背景。
问题在于,当选择TableViewCell
时,下面的图形完全隐藏,看起来很奇怪。我需要创建自定义selectedBackgroundView
才能解决此问题。问题是该视图需要在已存在的图形上创建蓝色渐变色调,并且我不知道如何绘制CGRect
或类似的部分透明的东西。
答案 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];