簡體   English   中英

在iPhone上已選擇如何更改圖像的圖標以表示圖像

[英]How to change the icon of an image to represent it has been selected on an iPhone

我正在嘗試模擬與在iPhone OS 3.X-4.0上找到的默認“照片”應用程序相同的行為。 基本上,當用戶通過圖像庫中的UIImagePickerController在“相冊”中選擇多張照片時,圖像上會出現一個圖標(對勾),表示用戶已選擇該圖像。 如何實現此功能。

非常感謝

用勾號圖像創建另一個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];
}
[_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:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM