简体   繁体   English

我没有阴影

[英]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 = YEScornerRadius = 25的内部子层。

just remove this line: 只需删除此行:

inLayer.masksToBounds=YES;

your code works fine 您的代码工作正常

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我只是听不到AudioFileReadPackets - I just don't get AudioFileReadPackets 为什么我没有从 eBay 获得产品价格的响应? - Why don't I get product price in responce from eBay? 为什么我不赞成使用“ shouldAutorotateToInterfaceOrientation:”警告 - Why don't i get a deprecated warning for “shouldAutorotateToInterfaceOrientation:” Objective-C的代表和事件设计(我不明白) - objective-c delegates and events design (I don't get it) 我没有AirPlayFeature - I don't have AirPlayFeature UILabel文本阴影不能是任何颜色而是灰色 - Can't get UILabel text shadow to be any color but gray 我不知道为什么我得到EXC_BAD_ACCESS(如使用@property保留) - I don't know why I get EXC_BAD_ACCESS ( As Using @property retain ) 为什么我不能设置按钮的阴影颜色? - Why can't I set my button's shadow colour? 如果我不同时为iPhone和iPad创建单独的xib,我的通用应用程序会被拒绝吗? - Will my universal app get rejected if I don't create separate xibs for both iPhone and iPad? 简单游戏的逻辑问题,我碰壁了,不知道该如何克服……SOS! - Problem with a simple game's logic, I have hit a wall, and don't know how to get over it…SOS!
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM