-2

I have been trying to fetch data from JSON to the label of collection view cell. I need to display name and age within a same label and city and distance within a same label just like this.

enter image description here.

I have already done fetching data but by taking different labels for all the four of them. How can i do the same thing in two different labels.

3 Answers3

0

you can do that by following:

self.LabelName.text=[NSString stringWithFormat:@"%@ , %@",name,age];
Muthukumar
  • 62
  • 12
0
NSDictionary *json = @{@"name":@"dave123", @"age":@"50"};
NSString *name = json[@"name"];
NSString *age = json[@"age"];

UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 64, 320, 40)];
[nameLabel setText:[NSString stringWithFormat:@"%@ (%@)", name, age]];
[self.view addSubview:nameLabel];
emotality
  • 12,795
  • 4
  • 39
  • 60
0

You can use stringWithFormat:

str1 = @"test1";
str2 = @"test2";
yourLabel =  [NSString stringWithFormat:@"str1:%@ and str2:%@", str1, str2];

yourLabel -> str1:test1 and str2:test2

user1841492
  • 161
  • 2
  • 2
  • 11