ios - 如何只为右侧添加阴影?

标签 ios uiview dropshadow

我正在像这样添加阴影。

vwVertical=[[UIView alloc] init];
[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;
[vwBlock addSubview:vwVertical];

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

最佳答案

您需要做的就是将 View 的边界插入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;

关于ios - 如何只为右侧添加阴影?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41415231/

相关文章:

ios - Swift 变量作用域问题

iphone - 从其他 View Controller 更改 UIView(在 Nib 内)背景

shadow - CSS中box-shadow和-moz-box-shadow的具体解释是什么?

winapi - Win32 : How to make drop shadow honor non-rectangular Layered window?

android - 如何避免 XMLHttpRequest 凭证(NTLM)被缓存在 phonegap/cordova 中?

iphone - Core Data iPhone - 在一张表上更新并从另一张表中删除

iphone - uiimage 未正确放入 subview 中

html - DisplayObject 上的过滤器不起作用

ios - 架构 armv7 的 undefined symbol : "_OBJC_CLASS_$_Crashlytics", 从 : objc-class-ref in AppDelegate. o 引用

iphone - 将 TextView 动画到顶部并增加高度