How to change the icon of an image to represent it has been selected on an iPhone
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 UI开发者_开发知识库ImagePickerController 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
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];
}
[_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:
精彩评论