如何为UIImageView应用CornerRadius和Shadow Offset

时间:2015-02-09 11:52:04

标签: ios uiimageview ios7.1 quartz-core

我正在开发一个电子商务应用程序。我需要使用shadowOffset在圆角处显示产品列表图像。两者都没有合作。我尝试了很多解决方案,但没有人解决我的问题。任何帮助将是一个欣赏。

更新代码:

UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(20,260,45,45)];
imageView.backgroundColor = [UIColor grayColor];
UIImage *image = [UIImage imageNamed:@"sample.png"];
imageView.image = image;

UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:imageView.bounds
                                               byRoundingCorners:UIRectCornerAllCorners
                                                     cornerRadii:CGSizeMake(22.5, 22.5)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = imageView.bounds;
maskLayer.path = maskPath.CGPath;
[imageView.layer setMask:maskLayer];

[imageView.layer setShadowOffset:CGSizeMake(0, 3)];
[imageView.layer setShadowOpacity:0.4];
[imageView.layer setShadowRadius:3.0f];
[imageView.layer setCornerRadius:22.0f];
imageView.layer.shadowColor=[UIColor redColor].CGColor;
imageView.layer.borderColor=[UIColor blackColor].CGColor;
imageView.layer.borderWidth=1.0;
[self.view addSubview:imageView];

谢谢&问候 Sam.P

0 个答案:

没有答案