我一直在尝试各种方法,但都没有成功。我只想做一个带有圆角、投影和背景图案的标签。如果我不想要圆角,阴影就能实现。但我无法同时实现它们!
这是我的代码,已经包含了投影:
这个代码可以为我提供没有圆角的阴影。但是如果我使用
这将给我圆角但没有阴影。我已经采用了使用阴影路径的建议,因此带有阴影路径的代码如下:
这段代码确实给我提供了圆角,但没有阴影。有什么建议吗?
谢谢!
这是我的代码,已经包含了投影:
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;
这段代码确实给我提供了圆角,但没有阴影。有什么建议吗?
谢谢!