2011-07-28 59 views

回答

0

您可以使用自定義按鈕代替uiimageviews
您可以使用此代碼在相機的按鈕中添加圖像。

- (void)selectPhotos 
{ 
    UIImagePickerController *picker = [[UIImagePickerController alloc] init]; 
    picker.sourceType = UIImagePickerControllerSourceTypeCamera; 
    picker.delegate = self; 
    [self presentModalViewController:picker animated:YES]; 
    [picker release]; 
} 

- (void)imagePickerController:(UIImagePickerController *)picker 
     didFinishPickingImage:(UIImage *)image 
        editingInfo:(NSDictionary *)editingInfo 
{ 
    [button setImage:image forState:UIControlStateNormal]; 
    [[picker parentViewController] dismissModalViewControllerAnimated:YES]; 
} 

然後在選擇方法,你可以從按鈕retrive像這樣

button.imageView.image 
+0

使用按鈕是一種有趣的方式!我會嘗試。非常感謝你! –

0

或...你可以使用的UIImageViews作爲

-(void)DrawImageViews:(UIImage*)fImage{ 

float start_X=2.0; 
float start_Y_image=2.0; 

for(int idx=0;idx<12;idx++) 
{ 
    UIImageView *imageView = [ [ UIImageView alloc ] initWithFrame:CGRectMake(start_X, start_Y_image, 78, HEIGHT)]; 
    imageView.image=fImage; 

    [self addSubview:imageView]; 
    [imageView release]; 

    if((idx+1)%4==0 && idx!=0) { 
     start_X=2.0; 
     start_Y_image += HEIGHT+2; 
    } 
    else 
     start_X += 78 + 2; 
    }} 

這裏我已經畫了12次相同的圖像,並在兩側保持2的填充。然後,你可以找到它的行和列使用委託方法挖掘:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ 
UITouch *touch =[touches anyObject]; 
CGPoint currentPoint =[touch locationInView:self]; 

NSInteger column = ((NSInteger)((currentPoint.x)/80) + 1); 
NSInteger row = ((NSInteger)((currentPoint.y)/(HEIGHT + 2) + 1);} 

我已經局部聲明的行和列在這裏。你必須從外面訪問!