合并2张图片用于配件视图

时间:2011-05-27 23:05:10

标签: iphone

我有两张图像,我想并排加入并在配件视图中显示。

 CGSize itemSize = CGSizeMake(40, 40);
 UIGraphicsBeginImageContext(itemSize);
    CGRect imageRect = CGRectMake(20.0, 20.0, 20, 20);
    [[UIImage imageNamed:@"homesmall.png"] drawInRect:imageRect];
    CGRect imageRect1 = CGRectMake(0.0, 0.0, 20, 20);
    [[UIImage imageNamed:@"update.png"] drawInRect:imageRect1];

    UIImageView *statusImageView = (UIImageView *) cell.accessoryView;

    statusImageView.image= UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

我试图把两个图像并排放在一边但不知道什么都没有进入附件视图。

1 个答案:

答案 0 :(得分:1)

[cell accessoryView]是UIView,而不是UIImageView。而且我不明白你为什么要绘制你的图像,因为你已将它们放在捆绑中。

为什么不:

UIImageView * image1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"homesmall.png"]];
UIImageView * image2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"update.png"]];

[image1 setFrame:CGRectMake(0,0,20,20)];
[image2 setFrame:CGRectMake(20,0,20,20)];

UIView * cellAcc = [[UIView alloc] initWithFrame:CGRectMake(0,0,40,40)];

[cellAcc addSubview:image1];
[cellAcc addSubview:image2];

[cell setAccessoryView:cellAcc];

[image1 release];
[image2 release];
[cellAcc release];