我有以下代码:
self.navigationBar_.layer.shadowColor = [UIColor blackColor].CGColor;
self.navigationBar_.layer.shadowOpacity = 0.3f;
self.navigationBar_.layer.shadowOffset = CGSizeMake(0.0f, 0.0f);
self.navigationBar_.layer.shadowRadius = 3.0f;
self.navigationBar_.layer.masksToBounds = NO;
我基本上只想将边框添加到底部,而不是整个矩形。我该怎么做呢?上面的代码也会在左边,右边,上边框上添加阴影。
答案 0 :(得分:4)
您可以使用渐变来代替图层阴影。您可以使用透明的PNG渐变,但这是一个如何以编程方式执行此操作的示例:
UIView *topShadowView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.navigationBar.bounds.size.width, 10)];
CAGradientLayer *topShadow = [CAGradientLayer layer];
topShadow.frame = CGRectMake(0, 0, self.navigationBar.bounds.size.width, 10);
topShadow.colors = [NSArray arrayWithObjects:(id)[[UIColor colorWithWhite:0.0 alpha:0.25f] CGColor], (id)[[UIColor clearColor] CGColor], nil];
[topShadowView.layer insertSublayer:topShadow atIndex:0];
[self.view addSubview:topShadowView];