【发布时间】:2011-07-29 07:37:08
【问题描述】:
我正在开发一个应用程序,我有一个 imageView 可以通过使用 imageView 的 image 属性向其添加图像。但是在我将图像添加到 imageView 之前,我想在右侧添加阴影效果的图像视图。 我在堆栈溢出中找到了很多答案,我被要求调用 drawInRect 方法中的代码,这可以在我在 imageView 上绘制图像时完成。但是我添加图像是为了让它看起来更丰富,我的图像是最好的质量。
有人可以建议我一个方法吗?
我想要的最终图像看起来像
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellIdentifier=@"identifier";
[[ListDataSource sharedDataSource] loadFiles];
ShelfCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell==nil) {
cell=[[[ShelfCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifier] autorelease];
}
cell.backgroundColor=[UIColor greenColor];
if (indexPath.row%2==0) {
cell.imageView1.image=[[ListDataSource sharedDataSource] dataAtIndex:(indexPath.row*4)+0].titleImage;
cell.imageView2.image=[[ListDataSource sharedDataSource] dataAtIndex:(indexPath.row*4)+1].titleImage;
cell.imageView3.image=[[ListDataSource sharedDataSource] dataAtIndex:(indexPath.row*4)+2].titleImage;
cell.imageView4.image=[[ListDataSource sharedDataSource] dataAtIndex:(indexPath.row*4)+3].titleImage;
cell.imageView5.image=nil;
}else {
cell.rackImage.frame=CGRectMake(128, bookHeight-5, 570, 60);
cell.imageView1.image=nil;
cell.imageView2.image=[[ListDataSource sharedDataSource] dataAtIndex:(indexPath.row*4)+0].titleImage;
cell.imageView3.image=[[ListDataSource sharedDataSource] dataAtIndex:(indexPath.row*4)+1].titleImage;
cell.imageView4.image=[[ListDataSource sharedDataSource] dataAtIndex:(indexPath.row*4)+2].titleImage;
cell.imageView5.image=[[ListDataSource sharedDataSource] dataAtIndex:(indexPath.row*4)+3].titleImage;
}
return cell;
}
**ShelfCell.m**
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
imageView1=[[UIImageView alloc] init];
imageView1.frame=CGRectMake(10, 15, 110, 150);
imageView1.layer.masksToBounds=NO;
imageView1.layer.shadowRadius=5;
imageView1.layer.shadowOpacity=0.5;
imageView1.layer.shadowPath=[UIBezierPath bezierPathWithRect:imageView1.frame];
imageView1.layer.shadowColor = [[UIColor blackColor] CGColor];
imageView1.layer.shadowOffset = CGSizeMake(5,5);
[self.contentView addSubview:imageView1];
imageView2=[[UIImageView alloc] init];
imageView2.frame=CGRectMake(CGRectGetMaxX(imageView1.frame)+30, 15, 110, 150);
[self.contentView addSubview:imageView2];
imageView3=[[UIImageView alloc] init];
imageView3.frame=CGRectMake(CGRectGetMaxX(imageView2.frame)+30, 15, 110, 150);
[self.contentView addSubview:imageView3];
imageView4=[[UIImageView alloc] init];
imageView4.frame=CGRectMake(CGRectGetMaxX(imageView3.frame)+30, 15, 110, 150);
[self.contentView addSubview:imageView4];
imageView5=[[UIImageView alloc] init];
imageView5.frame=CGRectMake(CGRectGetMaxX(imageView4.frame)+30, 15, 110, 150);
[self.contentView addSubview:imageView5];
}
return self;
}
**ListDataSource**
-(id)dataAtIndex:(NSUInteger)index{
if (index>=[arrayOfDataDirectories count]) {
return nil;
}
InfoDataSource *info = [[InfoDataSource alloc] init];
[info loadDirectoryAtPath:[arrayOfDataDirectories objectAtIndex:index]];
[info autorelease];
return info;
}
【问题讨论】:
标签: iphone ipad uiimageview