Fork me on GitHub

此程序包括UIProgressViewUIButton, UIDatePicker,UIAlert,UILabel,NSTimer

//

//  HViewController.h

//  Btn_lbl

//

//  Created by public on 13-7-18.

//  Copyright (c) 2013年  All rights reserved.

//

 

#import <UIKit/UIKit.h>

 

@interface HViewController : UIViewController

@property (retain, nonatomic) IBOutlet UIDatePicker *hdatePicker;

@property (retain, nonatomic) IBOutlet UILabel *lblText;

@property (retain, nonatomic) IBOutlet UIProgressView *progress;

@property (retain, nonatomic) IBOutlet UIProgressView *progressBar;

@property (retain, nonatomic) IBOutlet UIButton *btnStart;

@property (retain, nonatomic) IBOutlet UIButton *btnStop;

@property(retain,nonatomic)IBOutlet NSTimer* timer;

- (IBAction)btnClick:(id)sender;

- (IBAction)dateChange;

- (IBAction)startProgress:(id)sender;

- (IBAction)stopProgress:(id)sender;

- (IBAction)startHeadProgress:(id)sender;

@end

//

//  HViewController.m

//  Btn_lbl

//

//  Created by public on 13-7-18.

//  Copyright (c) 2013年 . All rights reserved.

//

 

#import "HViewController.h"

 

@interface HViewController ()

 

@end

 

@implementation HViewController

#pragma mark 加载数据

- (void)viewDidLoad

{

    [super viewDidLoad];

       // Do any additional setup after loading the view, typically from a nib.

    NSDate* hdate=[NSDate date];

    [_hdatePicker setDate:hdate animated:YES];

}

 

- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

 

- (void)dealloc {

    [_lblText release];

    [_hdatePicker release];

    [_progress release];

    [_timer release];

    [_btnStart release];

    [_progressBar release];

    [_btnStop release];

    [super dealloc];

}

#pragma mark -按钮的测试点击事件

- (IBAction)btnClick:(id)sender{

    UIButton * button=(UIButton *)sender;

    _lblText.font=[UIFont fontWithName:@"Bold" size:25];

    _lblText.backgroundColor=[UIColor blueColor];

    _lblText.textColor=[UIColor whiteColor];

    _lblText.text=@"中华";

    NSString* tittle=[NSString stringWithFormat:@"UILabel的内容是:%@,UIButton 的 tag 是 %d",_lblText.text,button.tag];

    NSString* message=[button currentTitle];

    UIAlertView* alert=[[UIAlertView alloc]initWithTitle:tittle message:message delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"cancel", nil];

    [alert show];

    [alert release];

   

}

#pragma mark -日历的改变

- (IBAction)dateChange {

    NSDate* date=[_hdatePicker date];

    NSDateFormatter *format=[[NSDateFormatter alloc]init];

    [format setDateStyle:NSDateFormatterShortStyle];

    [format setTimeStyle:NSDateFormatterShortStyle];

    _lblText.text=[NSString stringWithFormat:@"%@",[format stringFromDate:date]];

    [format release];

}

#pragma mark -Progress View进度条

-(void)changetimer

{

    _progress.progress+=0.001f;

    self.progressBar.progress+=0.001f;

   

}

- (IBAction)startProgress:(id)sender {

    _timer=[NSTimer scheduledTimerWithTimeInterval:0.03f target:self selector:@selector(changetimer) userInfo:nil repeats:YES];

    [_timer retain];

    [_btnStart setEnabled:NO];

    [_btnStop setEnabled:YES];

}

 

- (IBAction)stopProgress:(id)sender {

    [_timer invalidate];

    [_timer release];

    [_btnStart setTitle:@"继续" forState:UIControlStateNormal];

    UIColor *color=[UIColor blueColor];

    [_btnStart setTitleColor:color forState:UIControlStateNormal];

    [_btnStart setEnabled:YES];

    [_btnStop setEnabled:NO];

}

 

- (IBAction)startHeadProgress:(id)sender {

    _progress.progress=0.0f;

    _progressBar.progress=0.0f;

    [_btnStart setTitle:@"开始" forState:UIControlStateNormal];

    UIColor *color=[UIColor blueColor];

    [_btnStart setTitleColor:color forState:UIControlStateNormal];

}

@end

 

posted on 2013-07-19 11:30  lingfeng95  阅读(211)  评论(0编辑  收藏  举报