在视图上绘制阴影视图?

时间:2013-07-31 15:39:50

标签: ios cgcontext

我正在创建一个自定义视图来显示月份和日期,基本上就是这样:

enter image description here

但是,我还想在顶部的蓝色月份标签下方添加一个小三角形点。所以我在drawRect

中添加了以下代码
- (void)drawRect:(CGRect)rect
{
    [super drawRect:rect];
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextBeginPath(context);
    CGContextMoveToPoint(context, 30 - 5.0, 20);
    CGContextAddLineToPoint(context, 30 + 5.0, 20);
    CGContextAddLineToPoint(context, 30, 20 + 4.0);
    CGContextAddLineToPoint(context, 30 - 5.0, 20);
    CGContextSetRGBFillColor(context, 0, 118/255.0, 166/255.0, 1.0);
    CGContextFillPath(context);
}

这基本上是绘制白色日期标签,将小三角形添加到我的自定义视图中,它确实有效。但是它对日期标签本身进行着色会产生意想不到的副作用。效果如下:

enter image description here

此外,如果放大图像,您可以看到圆角也用黑色填充。看起来某些图层属性可能搞砸了?究竟发生了什么?

非常感谢!

0 个答案:

没有答案
相关问题