2017-10-17 09:57:10 poortess 阅读数 239
module.controller('MyCtrl', function($scope, $cordovaDatePicker) {

  var options = {
    date: new Date(),
    mode: 'date', // or 'time'
    minDate: new Date() - 10000,
    allowOldDates: true,
    allowFutureDates: false,
    doneButtonLabel: 'DONE',
    doneButtonColor: '#F2F3F4',
    cancelButtonLabel: 'CANCEL',
    cancelButtonColor: '#000000'
  };

  document.addEventListener("deviceready", function () {

    $cordovaDatePicker.show(options).then(function(date){
        alert(date);
    });

  }, false);
});
官网例子是这个,在IOS上模拟几次就挂掉了。解决方法是在每次调用时都重新set一个date近options中
options.date = new Date();
options只实例化1次的情况是有这样的Bug.
2013-09-25 12:04:24 xuqiang918 阅读数 26772

iOS上的选择时间日期的控件是这样的,左边是时间和日期混合,右边是单纯的日期模式。

,  

您可以选择自己需要的模式,Time, Date,Date and Time  , Count Down Timer四种模式。


步骤:1.新建一个Singe View Application工程 ,拖动一个DatePicker控件 和 Button到界面。

            2.然后关联Button事件(可以按住Ctrl拖动实现),如下图。

   


3.实现代码


- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    /*typedef enum {
        UIDatePickerModeTime,
        UIDatePickerModeDate,
        UIDatePickerModeDateAndTime,
        UIDatePickerModeCountDownTimer
    } UIDatePickerMode;
     */
    //datePicker.datePickerMode = UIDatePickerModeDateAndTime;//模式
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)datePick:(id)sender {
    NSDate *select  = [datePicker date];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yy-MM-dd HH:mm:ss"];
    NSString *dateAndTime = [dateFormatter stringFromDate:select];
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@" 时间提示" message: dateAndTime delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alert show];
    
}



效果如下



2012-12-24 16:27:53 xdrt81y 阅读数 11168

最近做项目遇到一个问题,在一个设置页面有两个输入框,想让用户敲击时,弹出日期控件,选择日期时间。Baidu了一遍,发现没有一个完整的解决方案,现在解决了,分享一下。

你可以用textfield的inputview和inputAccessoryView两个属性。创建datePicker,赋值给两个textfield的inputview属性。创建toolbar,包含一个Done按钮,赋值给inputAccessoryView属性。你需要用这个Done来退出inputview。

Done的事件处理:

if ( [textField1 isFirstResponder] ) {
    [textField1 resignFirstResponder];
} else if ( [textField2 isFirstResponder] ) {
    [textField2 resignFirstResponder];
}

Example

@interface CustomKeyboardAppDelegate : NSObject <UIApplicationDelegate> {
...

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITextField *textField;
@property (nonatomic, retain) IBOutlet UIToolbar *accessoryView;
@property (nonatomic, retain) IBOutlet UIDatePicker *customInput;

- (IBAction)dateChanged:(id)sender;
- (IBAction)doneEditing:(id)sender;
@end

在XIB文件中,拖出 一个UIToolbar和一个UIDatePicker,但不要附加到View中(拖到视图外面)。适当的连接Outlets。dateChanged:响应datepicker的ValueChanges,doneEditing:被ToolBar中的Done按钮点击时调用(Connection->Sent Actions->selectors)。以下是实现:

@implementation CustomKeyboardAppDelegate

@synthesize window=_window;
@synthesize textField = _textField;

@synthesize accessoryView = _accessoryView;
@synthesize customInput = _customInput;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.textField.inputView = self.customInput;
    self.textField.inputAccessoryView = self.accessoryView;
    ...    
}

...

- (IBAction)dateChanged:(id)sender {
    UIDatePicker *picker = (UIDatePicker *)sender;

    self.textField.text = [NSString stringWithFormat:@"%@", picker.date];
}

- (IBAction)doneEditing:(id)sender {
    [self.textField resignFirstResponder];
}
@end

 

正在学习过程中,错误之处请指正,欢迎交流,共同学习;

Demo:http://download.csdn.net/detail/xdrt81y/5858521

欢迎转载分享,请注明出处http://blog.csdn.net/xdrt81y

2013-01-23 21:42:37 caodongquan 阅读数 9
头文件里定义 label 和 datepicker


@interface ViewController : UIViewController
{
UILabel *dateLabel;
UIDatePicker *datePicker;
}

@property (nonatomic,retain)
IBOutlet UILabel *dateLabel;
@property(nonatomic,retain)
IBOutlet UIDatePicker *datePicker;

-(IBAction)dateChanged:(id)sender;

@end


m文件里边实现

@synthesize dateLabel;
@synthesize datePicker;
- (void)viewDidLoad
{
[super viewDidLoad];
NSDate *date = [NSDate date];
[datePicker setDate:date animated:YES];






-(IBAction)dateChanged:(id)sender
{
NSDate *curDate =[datePicker date];
NSDateFormatter *formate = [[NSDateFormatter alloc] init];
[formate setDateStyle:NSDateFormatterLongStyle];
[formate setTimeStyle:NSDateFormatterLongStyle];

NSString *formateDateString = [formate stringFromDate:curDate];
NSLog(@"string is %@" ,formateDateString);
dateLabel.text = [NSString stringWithFormat:
@"当前时间是 %@", formateDateString];
// [formate release];
}




[super viewDidLoad];
NSDate *date = [NSDate date];
[datePicker setDate:date animated:YES];
NSCalendar *cul =[NSCalendar currentCalendar];
NSDateComponents *com = [cul components:NSYearCalendarUnit|
NSMonthCalendarUnit|
NSDayCalendarUnit|
NSHourCalendarUnit|
NSMinuteCalendarUnit|
NSSecondCalendarUnit
fromDate:date];
NSLog(@"time is %d-%d-%d %02d:%02d:%02d",
[com year],
[com month],
[com day],
[com hour],
[com minute],
[com second]);

NSDateFormatter *formater =[[NSDateFormatter alloc]init];
[formater setDateFormat:@"YYYY-MM-DD"];
NSString *dl = [formater stringFromDate:date];
NSLog(@"CURRENT TIME %@",dl);
2017-10-23 14:19:00 weixin_33924312 阅读数 6

❗️ [Note] This project is deprecated and will be continued by https://github.com/VitaliiBlagodir/cordova-plugin-datepicker

DatePicker iOS Plugin for using PhoneGap / Cordova 3.0

This is a re-write of the iOS DatePicker plugin hosted on https://github.com/phonegap/phonegap-plugins/tree/master/iOS/DatePicker to run with PhoneGap/Cordova 3.0.

It includes more options and it is ready for using on iPhone and iPad.

Note: iOS6 only! For using iOS7 checkout the ios7 branch

Screen shots

iPhone

screen shot iPhone

iPad

screen shot iPad

Installation

  1. Make sure that you have Node and Cordova CLI or PhoneGap's CLI or Cordova Plugman installed on your machine.

Also you will need Xcode v.4.2 or newer to support the feature called "Automatic Reference Counting"

  1. Add a plugin to your project using Cordova CLI:
cordova plugin add https://github.com/sectore/phonegap3-ios-datepicker-plugin

Or using PhoneGap CLI:

phonegap local plugin add https://github.com/sectore/phonegap3-ios-datepicker-plugin

Or using plugman CLI:

plugman --platform ios --project ./platforms/ios --plugin https://github.com/sectore/phonegap3-ios-datepicker-plugin

3a) Register plugin within config.xml of your app

<feature name="DatePicker">
    <param name="ios-package" value="DatePicker"/>
</feature>

3b) If you are using PhoneGap build service add to config.xml

<gap:plugin name="de.websector.datepicker" />
  1. The clobber definition of the plugin is called datePicker. So you can reference to the plugin from anywhere in your code.

Example:

// defining options
var options = {
  date: new Date(),
  mode: 'date'
};
// calling show() function with options and a result handler
datePicker.show(options, function(date){
  console.log("date result " + date);  
});

Check section "Options" below to see all options.

Options

mode

The mode of the date picker.

Typ: String

Values: "date" / "time" / "datetime"

Default: 'datetime'

date

Selected date.

Typ: String

Default: new Date()

allowOldDates

Shows or hide dates earlier then selected date.

Typ: Boolean

Values: true / false

Default: true

allowFutureDates

Shows or hide dates after selected date.

Typ: Boolean

Values: true / false

Default: true

minDate (new)

Minimum date.

Typ: Date or empty String

Default: '' (empty String)

maxDate (new)

Maximum date.

Typ: Date or empty String

Default: '' (empty String)

doneButtonLabel (new)

Label of done button.

Typ: String

Default: 'Done'

doneButtonColor (new)

Hex color of done button.

Typ: String

Default: '#0000FF'

cancelButtonLabel (new)

Label of cancel button.

Typ: String

Default: 'Cancel'

cancelButtonColor (new)

Hex color of cancel button.

Typ: String

Default: '#000000'

x (new)

X position of date picker (iPad only). The position is absolute to the root view of the application.

Typ: String

Default: '0'

y (new)

Y position of date picker (iPad only). The position is absolute to the root view of the application.

Typ: String

Default: '0'

Requirements

  • PhoneGap 3.0 or newer /Cordova 3.0 or newer
  • iOS 5/6

Author of migration to PhoneGap 3.0

Jens Krause // WEBSECTOR.DE

Bitdeli Badge

转载于:https://my.oschina.net/u/199525/blog/1554858

没有更多推荐了,返回首页