在UIImageView上设置shadowColor属性时出现问题

wst*_*str 2 uiimageview ios

NSString *imgPath = [[jsonObjects objectAtIndex:indexPath.row] valueForKey:@"image"];
NSData *imgData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:imgPath]];
UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(20, 7, 44, 44)];
img.image = [UIImage imageWithData:imgData];
img.layer.shadowColor = [UIColor blackColor];
img.layer.shadowOffset = CGSizeMake(1, 2);
[cell addSubview:img];
[imgPath release];
[imgData release];
[img release];
Run Code Online (Sandbox Code Playgroud)

使用此代码时,我收到以下警告:

从不兼容的指针类型传递'setShadowColor:'的参数1

代码编译得很好,图像显示正确,但没有阴影.

我究竟做错了什么?

Mic*_* A. 6

我想这有点晚了.

正如Dasdom已经写道:

img.layer.shadowColor = [[UIColor blackColor] CGColor];
img.layer.shadowOpacity = 1.0f;
img.layer.shadowRadius = 8.0f;
Run Code Online (Sandbox Code Playgroud)

但是你必须确保imageView没有被剪裁到它的框架:

img.clipsToBounds = NO;
Run Code Online (Sandbox Code Playgroud)

迈克尔