如何更改图像的图标以表示已在 iPhone 上选择该图像

发布于 2024-09-27 02:59:32 字数 150 浏览 0 评论 0原文

我试图模拟与 iPhone OS 3.X-4.0 上的默认“照片”应用程序相同的行为。 基本上,当用户通过 UIImagePickerController 从图像库中选择相册中的多张照片时,图像上会出现一个图标(勾号),表示用户已选择该图像。如何实现这个功能。

非常感谢

I am trying to simulate the same behaviour as the defaults "Photos" application found on the iPhone OS 3.X-4.0.
Basically when the user selects multiple photos in the Album via the UIImagePickerController from the Image Library,an icon (tick mark) appears on the image to represent that the image has been selected by the user. How to implement this functionality.

Many thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

紧拥背影 2024-10-04 02:59:32

使用刻度线图像创建另一个 UIImageView 并将其作为子视图添加到所选的 UIImageView 中。像这样:

- (void)putCheckmarkOnImageView:(UIImageView *)anImageView {
    UIImageView *newIV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"checkmark.png"]];
    newIV.tag = 42;
    CGPoint newIVPosition = CGPointMake(anImageView.bounds.size.width - newIV.bounds.size.width, 
                                        anImageView.bounds.size.height - newIV.bounds.size.height);
    CGRect newFrame = newIV.frame;
    newFrame.origin = newIVPosition;
    newIV.frame = newFrame;
    [anImageView addSubview:newIV];
    [newIV release];
}   

- (void)removeCheckmarkOnImageView:(UIImageView *)anImageView {
    [[anImageView viewWithTag:42] removeFromSuperview];
}

create another UIImageView with the tickmark-image and add it as a subview to your selected UIImageView. Like this:

- (void)putCheckmarkOnImageView:(UIImageView *)anImageView {
    UIImageView *newIV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"checkmark.png"]];
    newIV.tag = 42;
    CGPoint newIVPosition = CGPointMake(anImageView.bounds.size.width - newIV.bounds.size.width, 
                                        anImageView.bounds.size.height - newIV.bounds.size.height);
    CGRect newFrame = newIV.frame;
    newFrame.origin = newIVPosition;
    newIV.frame = newFrame;
    [anImageView addSubview:newIV];
    [newIV release];
}   

- (void)removeCheckmarkOnImageView:(UIImageView *)anImageView {
    [[anImageView viewWithTag:42] removeFromSuperview];
}
何时共饮酒 2024-10-04 02:59:32
[_arrayOfCheckedPhotos addObject:anImageView.image];  // Same code, but add it to a mutable array
 // this is assuming you want the array of images

只需在发布之前将这行代码放在我上面的注释中^,稍后您就可以访问所有选定的图像,将数组设置为属性,以便轻松访问

,并且在removeCheckMark函数中说:

 [_arrayOfCheckedPhotos removeObjectAtIndex:
[_arrayOfCheckedPhotos addObject:anImageView.image];  // Same code, but add it to a mutable array
 // this is assuming you want the array of images

Just put that line of code before the release in the comment above mine^ than later you can access all of the selected images, make the array a property so its easily accessible

and also in the removeCheckMark function say:

 [_arrayOfCheckedPhotos removeObjectAtIndex:
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文