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

时间:2011-06-24 18:36:08

标签: ios uiimageview

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

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

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

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

我做错了什么?

3 个答案:

答案 0 :(得分:6)

我想这有点晚了。

正如Dasdom已写的那样:

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

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

img.clipsToBounds = NO;

迈克尔

答案 1 :(得分:0)

更改行

img.layer.shadowColor = [UIColor blackColor];

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

并添加

img.layer.shadowOpacity = 1.0f;
img.layer.shadowRadius = 8.0f;

答案 2 :(得分:0)

我想你应该试试这个:

sender.layer.shadowColor=[[UIColor yellowColor]CGColor];
sender.layer.shadowRadius=10;
sender.layer.shadowOffset=CGSizeMake(1, 1);
sender.layer.shadowOpacity=1;

此处发件人为UIButton类型。