-2

如何使用 nib 文件创建带有今天真实日期的标签?

谢谢

4

1 回答 1

1

不可能直接在 Interface Builder 中完成,您必须以编程方式完成。您应该连接(Google 类似 'IBOutlet')UILabel,然后添加此代码,例如在 viewDidLoad 中(其中 _label 是您链接的 UILabel):

NSDate *today = [NSDate date];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateStyle:NSDateFormatterShortStyle];
NSString *dateString = [dateFormat stringFromDate:today];
[_label setText:dateString];
于 2012-10-09T10:34:48.310 回答