I have a UILabel where I am saying whether is is an “A Day, B Day, etc.” Our school goes on an A-G day rotation so this is telling users what day today is. (The days are pulled from a large NSDictionary that matches up letter days with real dates)
I want to display a different image depending on what day it is. so something like
// (in pseudo-code)
if [UILabel == @"A Day"]{
image.image = [UIImage imageNamed:@"Aday.jpg"];
}
I am putting A Day into my label like this: [dictionary setObject:@"A Day" forKey:@"2012-05-15"]; then doing [letterday setText:[dictionary objectForKey:LetterDay]];.
Is there a way to use this same dictionary and do what I am trying above?
What would be the correct way to do this?
Thanks!
edit: this is what I have…still not working. Any tips?
NSMutableDictionary *imageforlabel = [[NSMutableDictionary alloc] init];
[imageforlabel setObject:[UIImage imageNamed:@"ADay.png"] forKey:@"A Day"];
[imageforlabel setObject:[UIImage imageNamed:@"BDay.png"] forKey:@"B Day"];
[imageforlabel setObject:[UIImage imageNamed:@"CDay.png"] forKey:@"C Day"];
[imageforlabel setObject:[UIImage imageNamed:@"DDay.png"] forKey:@"D Day"];
[imageforlabel setObject:[UIImage imageNamed:@"EDay.png"] forKey:@"E Day"];
[imageforlabel setObject:[UIImage imageNamed:@"FDay.png"] forKey:@"F Day"];
[imageforlabel setObject:[UIImage imageNamed:@"GDay.png"] forKey:@"G Day"];
rotationday.image = [imageforlabel objectForKey:letterday.TEXT];
Define an ivar
NSDictionary *imageForLabel, and set it up as follows in your designated initializer:Then at runtime look up the imgage from the
NSDictionary: