gpt4 book ai didi

ios - 如何在 objective-c 中给 imageView 标签

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:53:51 24 4
gpt4 key购买 nike

我正在为 children 开发一个应用程序。

 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);

// _img.image = selectedImage;

//cell.img.image=selectedImage;

}

我已经使用了 UIView。在 UIView 中,我放置了 15 个 ImageView。当我从输出中获得 selectedImage 时。我需要根据标签将图像放置在 ImageView 中。如何操作

最佳答案

您需要为 View 中的所有 15 张图像设置标签,例如 1,2,3,4,5...15

然后检查一下

for (int i = 0 ; i < randomNumber ; i++){
id subView = [view viewWithTag:i];

if ([subView isKindOfClass:[UIImageView class]]){
((UIImageView *)subView).image = selectedImage;
}

if ([subView isKindOfClass:[UIButton class]]){
[((UIButton *)subView) setImage:selectedImage forState:UIControlStateNormal];
}
}

说 randomNumber = 5 ,然后您可以为前 5 个 ImageView 设置图像。

关于ios - 如何在 objective-c 中给 imageView 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46403033/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com