我一直在尝试每一种方法,我发现,但我无法做到。我只是想制作一个带圆角的标签,一个带背景图案的阴影。只有当我不想要圆角时,影子才会起作用。我无法让他们在一起!UILabel带圆角,阴影和背景图案
这里是我的代码的影子:
label.text = msg;
label.textAlignment = UITextAlignmentCenter;
label.frame = CGRectMake(20,10,280,40);
label.backgroundColor
= [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"msg_box_bg.png"]];
[label.layer setCornerRadius:10];
[label.layer setMasksToBounds:NO];
/* Shadow */
label.layer.shadowColor = [UIColor blackColor].CGColor;
label.layer.shadowOpacity = 0.6;
label.layer.shadowOffset = CGSizeMake(0,0);
label.layer.shadowRadius = 3;
这给了我的影子没有圆角。但如果我使用
[label.layer setMasksToBounds:YES];
这将给我没有阴影的圆角。我已使用了阴影路径的提醒,所以用阴影路径的代码如下所示:
label.text = msg;
label.textAlignment = UITextAlignmentCenter;
label.frame = CGRectMake(20,10,280,40);
label.backgroundColor
= [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"msg_box_bg.png"]];
[label.layer setCornerRadius:10];
[label.layer setMasksToBounds:YES];
/* Shadow */
label.layer.shadowColor = [UIColor blackColor].CGColor;
label.layer.shadowOpacity = 0.6;
label.layer.shadowOffset = CGSizeMake(0,0);
label.layer.shadowRadius = 3;
label.layer.shadowPath = [[UIBezierPath bezierPathWithRoundedRect:label.frame cornerRadius:10]CGPath];
label.layer.shouldRasterize = YES;
此代码给我圆润的边角,但没有影子。 有什么建议吗?
谢谢!
http://stackoverflow.com/questions/3690972/why-maskstobounds-yes-prevents-calayer-shadow – 2012-04-19 01:35:51