我有2個圖像,我有4個iamges視圖,我想隨機在2-2圖像視圖上設置這2個圖像。如何在4個不同的圖像視圖上設置兩個圖像?
就像卡game.In用戶選擇1張卡,然後用戶有打開同一個圖像3個選項,如果圖像是相同的,然後用戶接一個地點擊贏得比賽。請幫助我...
int r =arc4random()%4;
int z=arc4random()%4;
UIImageView *imageView = (UIImageView *)[self.view viewWithTag:r];
imageView.image=[UIImage imageNamed:@"30-by-30-home"];
if(r!=z)
{
UIImageView *imageView = (UIImageView *)[self.view viewWithTag:z];
imageView.image=[UIImage imageNamed:@"30-by-30-home"];
}else{
if(r==3)
{
UIImageView *imageView = (UIImageView *)[self.view viewWithTag:z-2];
imageView.image=[UIImage imageNamed:@"30-by-30-home"];
}
if(r==0)
{
UIImageView *imageView = (UIImageView *)[self.view viewWithTag:z+2];
imageView.image=[UIImage imageNamed:@"30-by-30-home"];
}if(r==1)
{
UIImageView *imageView = (UIImageView *)[self.view viewWithTag:z+2];
imageView.image=[UIImage imageNamed:@"30-by-30-home"];
}
if(r==2)
{
UIImageView *imageView = (UIImageView *)[self.view viewWithTag:z-2];
imageView.image=[UIImage imageNamed:@"30-by-30-home"];
}
}
確保標籤是不同 – Dhara 2013-03-04 09:03:51
什麼是「Z」代表? – Apurv 2013-03-04 09:23:11
int z = arc4random()%4; – virant 2013-03-04 09:25:35