//倒計時 @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; }