まず最初に、私を助けてくれてありがとうと言いたいです。
Xcodeを使用してラベルに日付を作成する方法を知りたいのですが、日付はiPhoneのように同じ日付に従います。
ありがとう
まず最初に、私を助けてくれてありがとうと言いたいです。
Xcodeを使用してラベルに日付を作成する方法を知りたいのですが、日付はiPhoneのように同じ日付に従います。
ありがとう
これが1つの簡単なアプローチです
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
//uncomment to get the time only
//[formatter setDateFormat:@"hh:mm a"];
//[formatter setDateFormat:@"MMM dd, YYYY"];
[formatter setDateStyle:NSDateFormatterMediumStyle];
//get the date today
NSString *dateToday = [formatter stringFromDate:[NSDate date]];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320.0f, 20.0f)];
[label setText:dateToday];
[formatter release];
//then add to a view
日付は、以下のようにフォーマットしてラベルに設定できます。
NSDate *today = [NSDate date];
NSDateFormatter *dformat = [[NSDateFormatter alloc] init];
[dformat setDateFormat:@"dd:MM:YYYY"];
myLabel.text = [dformat stringFromDate:today];
テキスト日付の作成は簡単ですが、実際の問題は、日付テキストを作成するデータ ソースは何かということです。