[英]change the image using label.text value
I have one lable
called post.label.text = 5
. 我有一个叫post.label.text = 5
lable
。 And I have 30 image view which size is 8 X 8. by default i have small dot image. 我有30个图像视图,大小为8 X8。默认情况下,我有小点图像。 When the value of my post.label.text
is 5 , i need to change some of the 5 image out of 30 image should change to big dots image 当我的post.label.text
值为5时,我需要将30张图片中的5张图片更改为大点图片
ie: 即:
total image small dots = 30 image dots
should change from small to big dots = 5 image dots
I know to use if condition , but i have 30 images and for example if my post.label.text = 1
means i need to show only one small dot images to big dot image. 我知道要使用if condition,但是我有30张图像,例如,如果我的post.label.text = 1
意味着我只需要显示一个小点图像到大点图像。
Please help me. 请帮我。 i am new to ios.Thanks in advance! 我是ios新手,谢谢!
My image declaation is like this: 我的图像散列是这样的:
@property (weak, nonatomic) IBOutlet UIImage *dot1;
up to
@property (weak, nonatomic) IBOutlet UIImage *dot30;
And i did @synch of all dots 1 to 30
in .m file. 我在.m文件中@synch of all dots 1 to 30
进行了@synch of all dots 1 to 30
。 after that what should i do to change the dots image based on the label.text
value 之后,我该怎么做才能根据label.text
值更改点图像
I have more images so using if i cant change each image to chnage from small to big dots. 我有更多图像,因此如果我无法将每个图像从小点更改为大点,请使用。 IS there any idea to do. 有什么想法要做。 Please explain with some code. 请解释一些代码。
I did in this way: 我这样做:
if (sLabel.text > 10) {
// imgV.image = [UIImage imageNamed:@"small dot.png"];
}
but how i will do for all value for >1 , >2, so on. 但是我将如何处理> 1、2的所有值,依此类推。 Please help me 请帮我
Try this Joseph
self.post.text =@"5";
int value = [self.post.text intValue];
for (int i=0; i<value; i++) {
UIImage *images =[UIImage imageNamed:[NSString stringWithFormat:@"dot%d",i]];
imgV.image = images;
}
Create connection outlet of all image properties; 创建所有图像属性的连接出口;
@property IBOutletCollection(UIImageView) NSArray *imgArray;
Next - 下一个 -
self.post.text = @"5";
int postValue = [self.post.text intValue];
for (int i=29; i>(29-postValue); i--)
{
UIImageView *currImageView = [self.imgArray objectAtIndex:i];
currImageView.image = [UIImage imageNamed:@"big dot.png"];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.