标签:
//倒计时 @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(jishi) userInfo:nil repeats:YES]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } -(void)jishi{ //转化成本地时间 NSDate *beginDate = [[NSDate alloc]init]; NSString *endtime=@"2015-11-14 00:00:00 +00"; NSDateFormatter *format = [[NSDateFormatter alloc]init]; [format setDateFormat:@"yyyy-MM-dd HH:mm:ss +hh"]; NSDate *endDate = [format dateFromString:endtime]; NSString *beg=[format stringFromDate:beginDate]; NSLog(@"%@,%@",beg,endDate); _begin.text=beg; NSMutableString *string = [[NSMutableString alloc]init]; NSTimeInterval timeDif = [endDate timeIntervalSince1970]-[beginDate timeIntervalSince1970]; int shi= timeDif/3600; int fen= (timeDif-(shi*60*60))/60; int miao=timeDif-(shi*60*60)-(fen*60); [string appendString:[NSString stringWithFormat:@"%i-%i-%i",shi,fen,miao]]; // NSLog(@"%@",string); _countDown.text=string; // _countDown.text=string; _end.text=[NSString stringWithFormat:@"%@",[format stringFromDate:endDate]]; } //UIIMage - (void)viewDidLoad { [super viewDidLoad]; _i=20; //图片实例化方法一: UIImageView * imageView = [ [ UIImageView alloc ] init ] ; //图片实例化方法二: UIImageView * imageViewI = [ [ UIImageView alloc ] initWithFrame: CGRectMake ( 10, 10, 200, 200 ) ] ; //设置ImageView的内容 imageViewI.image = [ UIImage imageNamed:@"0" ] ; //图片实例化方法三: UIImageView * imageViewII = [ [ UIImageView alloc ] initWithImage : [ UIImage imageNamed : @"4" ] ] ; //设置imageView的大小 imageViewII.frame = CGRectMake ( 180, 100, 100, 100 ) ; //图片实例化方法四:(图片两个状态) _imageViewIII = [ [ UIImageView alloc ] initWithImage : [ UIImage imageNamed:@"1" ] highlightedImage : [ UIImage imageNamed:@"2" ] ] ; _imageViewIII.frame = CGRectMake ( 5,5, 100, 100 ) ; //将图片添加到页面上 [ self.view addSubview:_imageViewIII ] ; //添加按钮控制图片状态 UIButton * button = [ [ UIButton alloc ] initWithFrame : CGRectMake ( 80, 80, 180, 30 ) ] ; [ button setTitle : @"高亮切换" forState : UIControlStateNormal ] ; button.backgroundColor = [ UIColor redColor ] ; [ button addTarget : self action : @selector(gaoLiang) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button]; // ========= 关于图片的手势 ======== _imageViewIIII = [ [ UIImageView alloc ] initWithImage : [ UIImage imageNamed:@"4" ] ]; _imageViewIIII.frame = CGRectMake(10, 150, 100, 100); _imageViewIIII.backgroundColor=[UIColor redColor];//可以给图片添加背景颜色明确image和imageView的差别 //将图片添加到页面上 [self.view addSubview:_imageViewIIII]; //图片支持交互 _imageViewIIII.userInteractionEnabled = YES; // 定义手势 UITapGestureRecognizer *gestur = [ [ UITapGestureRecognizer alloc ]initWithTarget:self action:@selector(shouShi) ]; // 将图片添加手势 [_imageViewIIII addGestureRecognizer:gestur]; // =========== 图片旋转 ============ _rotationImageView = [[ UIImageView alloc]initWithImage:[ UIImage imageNamed:@"0" ] ] ; _rotationImageView.frame=CGRectMake(200, 200, 100, 100); [self.view addSubview:_rotationImageView]; //添加按钮控制图片状态 UIButton * buttonI = [ [ UIButton alloc ] initWithFrame : CGRectMake ( 200, 150, 80, 30 ) ] ; [ buttonI setTitle : @"图片旋转" forState : UIControlStateNormal ] ; buttonI.backgroundColor = [ UIColor redColor ] ; [ buttonI addTarget : self action : @selector(xuanZhuan) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:buttonI]; // =========== 图片放缩 ============ _changeSizeImageView = [[ UIImageView alloc]initWithImage:[ UIImage imageNamed:@"2" ] ] ; _changeSizeImageView.frame=CGRectMake(20, 300, 100, 100); [self.view addSubview:_changeSizeImageView]; //添加按钮控制图片放大 UIButton * buttonBig = [ [ UIButton alloc ] initWithFrame : CGRectMake ( 110, 320, 80, 30 ) ] ; [ buttonBig setTitle : @"图片放大" forState : UIControlStateNormal ] ; buttonBig.backgroundColor = [ UIColor redColor ] ; [ buttonBig addTarget : self action : @selector(fangDa) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:buttonBig]; //添加按钮控制图片缩小 UIButton * buttonSmall = [ [ UIButton alloc ] initWithFrame : CGRectMake ( 110, 360, 80, 30 ) ] ; [ buttonSmall setTitle : @"图片缩小" forState : UIControlStateNormal ] ; buttonSmall.backgroundColor = [ UIColor redColor ] ; [ buttonSmall addTarget : self action : @selector(suoXiao) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:buttonSmall]; //====== 利用Frame控制缩放 ====== _changeFrameImageView = [[ UIImageView alloc]initWithImage:[ UIImage imageNamed:@"5" ] ] ; _changeFrameImageView.frame=CGRectMake(120, 430, 100, 100); [self.view addSubview:_changeFrameImageView]; //添加按钮控制图片放大 UIButton * frameBig = [ [ UIButton alloc ] initWithFrame : CGRectMake ( 110, 600, 50, 30 ) ] ; [ frameBig setTitle : @"放大" forState : UIControlStateNormal ] ; frameBig.backgroundColor = [ UIColor redColor ] ; [ frameBig addTarget : self action : @selector(zengDa) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:frameBig]; //添加按钮控制图片缩小 UIButton * frameSmall = [ [ UIButton alloc ] initWithFrame : CGRectMake ( 220, 600,50, 30 ) ] ; [ frameSmall setTitle : @"缩小" forState : UIControlStateNormal ] ; frameSmall.backgroundColor = [ UIColor redColor ] ; [ frameSmall addTarget : self action : @selector(bianXiao) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:frameSmall]; // _imageViewIII.center=CGPointZero;//设置图片中心位置,CGPointZero是原点(0,0) // [self.view bringSubviewToFront:imageViewI];//将控件移至最前方 // _imageViewIIII.contentMode=UIViewContentModeCenter; // _imageViewIII.transform=CGAffineTransformMakeTranslation(100, 200); } //添加按钮控制图片放大回调方法 -(void)fangDa{ _changeSizeImageView.transform=CGAffineTransformMakeScale(2, 5); } //添加按钮控制图片缩小回调方法 -(void)suoXiao{ _changeSizeImageView.transform=CGAffineTransformMakeScale(0.2, 0.5); } //图片放大回调方法 -(void)zengDa{ CGRect bonus = _changeFrameImageView.bounds;//图片中心为中点 bonus.size.width += 30; bonus.size.height += 30; _changeFrameImageView.bounds = bonus; } //图片缩小回调方法 -(void)bianXiao{ CGRect frame = _changeFrameImageView.frame;//图片左上角为中心 frame.size.height -= 30; frame.size.width -= 30; _changeFrameImageView.frame = frame; } //为切换高亮添加的方法 -(void)gaoLiang{ if (_imageViewIII.highlighted==YES) { _imageViewIII.highlighted=NO; }else{ _imageViewIII.highlighted=YES; } } -(void)shouShi{ NSLog(@"图片手势方法。。。"); } //点击图片旋转按钮调用的自定义方法,其中设置图片旋转多少 -(void)xuanZhuan{ _i+=20; _rotationImageView.transform=CGAffineTransformMakeRotation(M_PI*_i/180); // 这样的旋转是以图片中心为旋转中心的,旋转角度为:M_PI*?/180中?位置 } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end //DatePicker (void)viewDidLoad { [super viewDidLoad]; // UIDatePicker 是一个控制器类,他是UIControl的子类,专门用于接受日期、时间和持续时长的输入。日期选取器的各列会按照指定的风格进行自动配置 // UIDatePicker 依赖于 NSDate 类 _datePicker.minuteInterval=6; //设置datePicker的样式 _datePicker.datePickerMode=UIDatePickerModeDate; // 格式化一个字符串型的时间为NSDate类型 NSString *string=@"2012-12-22"; NSDateFormatter *formatter=[[NSDateFormatter alloc]init]; [formatter setDateFormat:@"yyyy-MM-dd"]; NSDate *date=[formatter dateFromString:string]; // 设置datePicker的最小时间 _datePicker.minimumDate=date; //对datePicker添加事件 [_datePicker addTarget:self action:@selector(dateChange:) forControlEvents:UIControlEventValueChanged]; } //当datePicker值发生改变会回调的自定义方法 -(void)dateChange:(UIDatePicker *)sender{ NSDate *date=_datePicker.date; NSLog(@"%@",date); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } //NSDate // insert code here... NSLog(@"Hello, World!"); //获取当前时间的方法有两个 NSDate * date = [ [ NSDate alloc ] init ] ; NSDate * dateI = [ NSDate date ] ; // 将NSDate转化为NSString NSDateFormatter * dateFormatter = [ [ NSDateFormatter alloc ]init ] ; [ dateFormatter setDateFormat : @"yyyy-MM-dd HH:mm:ss" ] ; NSString * nowTime = [ [ NSString alloc ] init ] ; nowTime = [ dateFormatter stringFromDate:dateI ] ; NSLog ( @" ==== %@ " , nowTime ); NSLog ( @" %@ ---- %@ " , date , dateI ) ; // 将字符串转化为date NSString * string = @"2013-12-25 12:23:57" ; NSDate * dateIII = [ dateFormatter dateFromString:string ] ; NSLog ( @"%@" , dateIII ) ; } return 0; }
[非凡程序员]倒计时 uiimage uiDatePicker NSDate
标签:
原文地址:http://my.oschina.net/u/2501648/blog/530095