1

我正在尝试在自定义视图下添加阴影,我有以下代码:

CGContextSaveGState(context);
CGContextSetShadow(context, CGSizeMake(0, 2), 3.0);
CGRect shadowRect = CGRectMake(self.bounds.origin.x,
                               self.bounds.origin.y + self.bounds.size.height,
                               self.bounds.size.width,
                               3.0);
CGContextFillRect(context, shadowRect);
CGContextRestoreGState(context);

但影子是看不见的。

4

1 回答 1

2

试试这个:

    UIColor *color = [UIColor grayColor];
    CGColorRef gray = color.CGColor;
    self.layer.shadowColor = gray;
    self.layer.shadowOffset = CGSizeMake(0, 0);
    self.layer.shadowRadius = 2;
    self.layer.shadowOpacity = 1;
    self.layer.borderColor = red;
    self.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.bounds].CGPath;
    self.layer.masksToBounds = NO;
于 2012-12-31T13:31:34.427 回答