[英]i don't get shadow
Here is my code: 这是我的代码:
CALayer *inLayer =[CALayer layer];
inLayer.backgroundColor = [UIColor redColor].CGColor;
inLayer.frame=CGRectMake(0,0,50, 50);
inLayer.position=CGPointMake(200, 200);
inLayer.cornerRadius=25;
inLayer.masksToBounds=YES;
inLayer.shadowColor=[UIColor blackColor ].CGColor;
inLayer.shadowOffset=CGSizeMake(5,10);
inLayer.shadowOpacity = 0.8;
inLayer.contents=(id)[UIImage imageNamed:@"Close.png"].CGImage;
inLayer.name=@"Close";
[self.view.layer addSublayer:inLayer];
i don't get shadow. 我没有阴影。 something i miss there?
我在那里想念的东西吗?
The shadow is drawn outside of the layer's bounds. 阴影绘制在图层边界之外。 You have to set
inLayer.masksToBounds = NO
to see the shadow. 您必须设置
inLayer.masksToBounds = NO
才能看到阴影。
Of course, that will prevent cornerRadius
from working. 当然,这将阻止
cornerRadius
工作。
You need to use two layers: an outer layer that sets the shadow, and an inner sublayer that sets masksToBounds = YES
and cornerRadius = 25
. 您需要使用两层:设置阴影的外层和设置
masksToBounds = YES
和cornerRadius = 25
的内部子层。
just remove this line: 只需删除此行:
inLayer.masksToBounds=YES;
your code works fine 您的代码工作正常
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.