![](/img/trans.png)
[英]How can I restrict the specific year in date picker in iPhone programatically?
[英]How can I display a specific text related to a specific date using date picker?
我是iOS的新手,我對它的所有API都不熟悉。 我發現了如何在文本字段中顯示所選日期,但是我不知道要寫什么來顯示與特定日期相關的特定(選定)文本。
這是我用來顯示日期的代碼。 您知道我需要更改什么才能能夠將自己的文本寫到特定日期嗎?:
#import "ViewController.h"
@implementation ViewController
@synthesize datePicker;
@synthesize dateLabel;
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[self setDateLabel:nil];
[self setDatePicker:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation (UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (IBAction)touchButton:(id)sender {
NSDate *dateSelect = [datePicker date];
NSString *dateStamp = [[NSString alloc]initWithFormat:@"The date is %@", dateSelect];
dateLabel.text = dateStamp;
}
@end
(我有一個按鈕,日期選擇器和一個文本字段)
非常感謝您的回答。
您必須使用格式化程序。 看一看...
...
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"HH:mm"]; <--- This will show hours and minutes
NSString *dateStamp = [formatter stringFromDate:date];
...
在setDateFormat中,可以通過這種方式設置所需的輸出格式...
dd-日MM-月yyyy-年HH-小時mm-分鍾ss-秒
...因此[formatter setDateFormat:@“ MM / dd / yyyy,HH:mm”]將為您提供類似“ 01/01/2013,13:45”的信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.