How to display text depending on quantity in UILabel

I am working on an application with some calculation function. I have UITextFieldwhere the user enters a number and UILabelwhere the result. How can I display the text in the second UILabeldepending on the number in the first UILabel?

Example:

If number in *firstLabel less than 20, then display in *secondLabel: small

If number in *firstLabel from 20 to 30, then display in *secondLabel: normal

If number in *firstLabel greater than 40, then display in *secondLabel: big

I hope you understand what I mean. Thank! Sorry for my English.

+3
source share
3 answers

you need to get the int value from firstLabel , which is saved as text, you can get it using a function NSString intValue.

Use below

int intValueFromFirstLabel = [firstLabel.text intValue];

if(intValueFromFirstLabel < 20)
{
  secondLabel.text = @"small";
}
else if(intValueFromFirstLabel >= 20 && intValueFromFirstLabel <= 30)
{
  secondLabel.text = @"normal";
}
else if(intValueFromFirstLabel > 40)
{
  secondLabel.text = @"big";
}
+3
source
if([firstLabel.text intValue] <20)
{
    secondLabel .text=@"small";
}
else if(([firstLabel.text intValue] >=20) && ([firstLabel.text intValue] <=30) )
{
    secondLabel .text=@"normal";
}
else if([firstLabel.text intValue] >30)
{
    secondLabel .text=@"big";
}
0
source

You can use this code

 lblFirst.text = txtField.text;
 int intValue = [lblFirst.text intValue];
 if (intValue < 20) {
    lblSecond.text = @"Small";
 } else if (intValue >= 20 && intValue <= 30) {
    lblSecond.text = @"Normal";
 } else if (intValue > 40) {
    lblSecond.text = @"Big";
 }
0
source

All Articles