【发布时间】:2014-02-10 02:24:24
【问题描述】:
我在自定义的 UIView 初始化中使用此代码:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
...
UIBezierPath *shadowPath = [UIBezierPath bezierPathWithRect:CGRectMake(frame.origin.x, frame.size.height, frame.size.width, 15)];
self.layer.masksToBounds = NO;
self.layer.shadowColor = [UIColor blackColor].CGColor;
self.layer.shadowOffset = CGSizeMake(0.0f, 4.0f);
self.layer.shadowOpacity = 0.5f;
self.layer.shadowPath = shadowPath.CGPath;
}
return self;
}
尝试制作这样的阴影:
1)
但我得到了这个效果:
2)
您可以看到这是我想要实现的颠倒版本。如何制作第一张图片的阴影效果?
【问题讨论】:
-
为什么你不这样做 UIBezierPath *shadowPath = [UIBezierPath bezierPathWithRect:view.bounds];
-
这条线将在整个视图上投下阴影。我只想让阴影出现在 UIView 的底部。