如何仅为右侧添加投影?

时间:2017-01-01 11:52:10

标签: ios uiview dropshadow

我正在添加这样的投影。

*.sh

但是这增加了阴影3面。我怎样才能添加到右侧。 请帮我。 感谢

1 个答案:

答案 0 :(得分:1)

您需要做的就是在top - left - bottom上插入视图的界限,然后使用shadow path

vwVertical=[[UIView alloc] init];
// Create edge insets
UIEdgeInsets contentInsets = UIEdgeInsetsMake(0, 10, 0, 0);
// Create rect with inset and view's bounds
CGRect shadowPathOnlyIncludingRight = UIEdgeInsetsInsetRect(vwVertical.bounds, contentInsets);
// Apply it on the layer's shadowPath property
vwVertical.layer.shadowPath = [UIBezierPath bezierPathWithRect:shadowPathOnlyIncludingRight].CGPath;

[vwVertical setBackgroundColor:[UIColor whiteColor]];
vwVertical.translatesAutoresizingMaskIntoConstraints = NO;
vwVertical.layer.shadowColor=[UIColor colorWithRed:32/255 green:59/255 blue:90/255 alpha:1.0].CGColor;
vwVertical.layer.shadowOffset=CGSizeMake(5, 0);
vwVertical.layer.shadowOpacity=0.12;
vwVertical.layer.shadowRadius=6.5;