【问题标题】:Core Graphics Transparent Overlay核心图形透明叠加
【发布时间】:2013-03-23 19:19:29
【问题描述】:
我将UITableViewCell 的背景视图替换为我自己的UIView 自定义子类,其中我用我自己的方法覆盖了drawRect 方法,从而创建了一个多色且不断变化的背景。
问题是当TableViewCell被选中时,下面的图形被完全隐藏了,看起来很奇怪。我需要创建一个自定义 selectedBackgroundView 来解决这个问题。问题是该视图需要在已经存在的图形上创建蓝色渐变色调,而我不知道如何绘制 CGRect 或类似的部分透明的东西。
【问题讨论】:
标签:
iphone
ios
objective-c
xcode
core-graphics
【解决方案1】:
// 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];