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

Ios 在UIImageView上设置shadowColor属性时出现问题,ios,uiimageview,Ios,Uiimageview,使用此代码时,我收到以下警告: 正在从不兼容的指针类型传递“setShadowColor:”的参数1 代码编译得很好,图像显示正确,但没有阴影 我做错了什么?换行 NSString *imgPath = [[jsonObjects objectAtIndex:indexPath.row] valueForKey:@"image"]; NSData *imgData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:imgPa

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

正在从不兼容的指针类型传递“setShadowColor:”的参数1

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

我做错了什么?

换行

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];

img.layer.shadowColor = [[UIColor blackColor] CGColor];

我想有点晚了

Dasdom已经写道:

img.layer.shadowOpacity = 1.0f;
img.layer.shadowRadius = 8.0f;
但您必须确保imageView未剪裁到其帧:

img.layer.shadowColor = [[UIColor blackColor] CGColor];
img.layer.shadowOpacity = 1.0f;
img.layer.shadowRadius = 8.0f;

迈克尔

我想你应该试试这个:

img.clipsToBounds = NO;

这里的发送者是
ui按钮
类型。

好的,现在警告消失了,但仍然没有阴影。也许我的方法不对?好的,尝试将阴影半径更改为2.0f。下一个(也是最后一个)想法:尝试将图像放入视图,并向视图添加阴影。
img.clipsToBounds = NO;
sender.layer.shadowColor=[[UIColor yellowColor]CGColor];
sender.layer.shadowRadius=10;
sender.layer.shadowOffset=CGSizeMake(1, 1);
sender.layer.shadowOpacity=1;