Okay your code looks good except you need to run initWithFrame on the label and you'd be creating a new label every time. I advise creating the label in IB and hooking an IBOutlet up. Then you just need to put a method name to it, I'm surprised that you didn't know how to do that but you knew how to write all that code. Also code tags next time please. [code] [1/CODE] Without the 1. So this is what it would look like with the label being created in IB and having a name of dateLabel.
Code:
- (void)setDateLabelWithCurrentDate {
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MMM dd"];
[formatter setDateStyle:NSDateFormatterMediumStyle];
NSString *dateToday = [formatter stringFromDate:[NSDate date]];
[formatter release];
[dateLabel setText:dateToday];
}
Just call the method like so:
Code:
[self setDateLabelWithCurrentDate];
whenever you want to set the label.