在objective-c中为多个imageView设置标记

时间:2017-09-26 04:17:51

标签: ios objective-c uiimageview

我正在为孩子们开发一款应用。

images=[[NSMutableArray alloc]initWithObjects:[UIImage imageNamed:@"Navarre-Family-Eye-Care-Navarre-Florida-Optometrist-Santa-Christmas-Toy-Safety.jpg"],[UIImage imageNamed:@"Christmas-Wallpapers-HD-Picture.jpg"],[UIImage imageNamed:@"Christmas-Wallpaper-jesus-9413550-1024-768.jpg"],[UIImage imageNamed:@"tree.jpg"],[UIImage imageNamed:@"luxury-christmas-napkins-father-christmas-1635-p.jpg"],[UIImage imageNamed:@"Navarre-Family-Eye-Care-Navarre-Florida-Optometrist-Santa-Christmas-Toy-Safety.jpg"],[UIImage imageNamed:@"Christmas-Wallpapers-HD-Picture.jpg"],[UIImage imageNamed:@"Christmas-Wallpaper-jesus-9413550-1024-768.jpg"],[UIImage imageNamed:@"tree.jpg"],[UIImage imageNamed:@"luxury-christmas-napkins-father-christmas-1635-p.jpg"], nil];

NSString *dd=[NSString stringWithFormat:@"%@", images];
NSLog(@"%@",dd);

randomIndex1=arc4random() % images.count;
selectedImage = [images objectAtIndex:randomIndex1]; //random selected image

NSLog(@"%@",selectedImage);

number = [[NSMutableArray alloc]initWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10", nil];

randomNumber = arc4random() % number.count; //random selected number
NSLog(@"%d",randomNumber);

for (int i = 0; i <randomNumber; i++)
{
  NSLog(@"%@", selectedImage);
}

for (int j = 0 ; j <= randomNumber ; j++){
    UIImageView *iv = [_v1 viewWithTag:j];
    iv.image = selectedImage;
}

我已将UIView放在viewController中。在UIView内部有15个图像视图。要获得所需的输出,我需要根据标记将所选图像放在imageView中。怎么做到这一点?

2 个答案:

答案 0 :(得分:0)

显示15张图片使用collectionView,

# ******************************************************** # # Winnings is the amount Max Won which is 1000000 # Years is a placeholder to define the variable # Loop winnings - 52000 and cound the amount of years, # until 52000 can not be withdrew from account # print the number of years. # # ******************************************************** def main(): winnings = 1000000 years = 0 while winnings >= 52000: years = years + 1 winnings = winnings - 52000 print("Number of years Max can withdraw 52000 is",years) main()

itemForRow

获取所选图像

使用DidSelectItem

cell.imageview.image = UIImage(named:arrImg[indexPath.row])

有关详细信息,请在问题中指明该内容。

答案 1 :(得分:0)

为什么不使用UICollection视图在水平/垂直方向上显示图像?另外,使用indexpath.item作为标记。使用collectionview单元格加载所有图像。 将图像路径/ url存储在数组中,并为索引路径方法加载它们的集合视图项。