多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > php開源 > 綜合技術 > NSTimer,UIActivityIndicatorView,UIProgressView等控件的使用方法

NSTimer,UIActivityIndicatorView,UIProgressView等控件的使用方法

來源:程序員人生   發布時間:2014-12-28 12:32:54 閱讀次數:4103次

說明

    本例子主要簡示了和時間相干的1些控件的用法,摹擬了1個下載器。

運行結果


主要代碼

@synthesize _labelInfo; @synthesize _textInfo; @synthesize _buttonDownload; @synthesize _processViewDownload; @synthesize _activityIndicatorDownload; @synthesize _sliderDownload; @synthesize _switchDownload; @synthesize _timerDownload; - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. _imageBackground = [UIImage imageNamed:@"leaf.jpg"]; self.view.backgroundColor = [UIColor colorWithPatternImage:_imageBackground]; // 位置大小預設值 CGFloat x = self.view.frame.size.width / 8; CGFloat y = self.view.frame.size.height / 10; CGFloat w = x * 6; CGFloat h = 40; CGFloat hEdge = 10; CGFloat cornerRadius = 10; // 標簽 _labelInfo = [[UILabel alloc] initWithFrame:CGRectMake(x, y, w, h)]; _labelInfo.text = @"綠豆豬下載"; _labelInfo.textColor = [UIColor greenColor]; _labelInfo.shadowColor = [UIColor redColor]; _labelInfo.shadowOffset = CGSizeMake(2, 3); _labelInfo.textAlignment = NSTextAlignmentCenter; NSArray* arrayFont = [UIFont familyNames]; _labelInfo.font = [UIFont fontWithName:arrayFont[arc4random()%arrayFont.count] size:h⑵]; [self.view addSubview:_labelInfo]; // 文本信息欄 y = _labelInfo.frame.origin.y + _labelInfo.frame.size.height; y += 2*hEdge; _textInfo = [[UITextField alloc] initWithFrame:CGRectMake(x, y, w, h)]; _textInfo.placeholder = @"Here is the app infomation list"; _textInfo.layer.cornerRadius = cornerRadius; _textInfo.backgroundColor = [UIColor whiteColor]; [self.view addSubview:_textInfo]; // 豬豬圖標按鈕 UIImage* imageStart = [UIImage imageNamed:@"pig.png"]; y = _textInfo.frame.origin.y + _labelInfo.frame.size.height; y += hEdge; _buttonDownload = [[UIButton alloc] initWithFrame:CGRectMake(x, y, w/4, h*2)]; [_buttonDownload setImage:imageStart forState:UIControlStateNormal]; _buttonDownload.backgroundColor = [UIColor clearColor]; [_buttonDownload addTarget:self action:@selector(onClickBtn:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:_buttonDownload]; // 下載唆使器 _activityIndicatorDownload = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(x+w/2, y, w/4, h)]; //[_activityIndicatorDownload startAnimating]; [self.view addSubview:_activityIndicatorDownload]; // 下載開關 _switchDownload = [[UISwitch alloc] initWithFrame:CGRectMake(x+3*w/4, y, w/4, h)]; [_switchDownload addTarget:self action:@selector(onSwitchChange:) forControlEvents:UIControlEventValueChanged]; [self.view addSubview:_switchDownload]; // 下載進度條 _processViewDownload = [[UIProgressView alloc] initWithFrame:CGRectMake(x + w/4, y + h, 3*w/4, h)]; _processViewDownload.progress = 0; [self.view addSubview:_processViewDownload]; // 下載文件唆使器 y = _buttonDownload.frame.origin.y + _buttonDownload.frame.size.height; y += hEdge; _sliderDownload = [[UISlider alloc] initWithFrame:CGRectMake(x, y, w, h)]; [self.view addSubview:_sliderDownload]; } -(IBAction)onClickBtn:(id)sender { _textInfo.text = @"This is green pig app."; } -(IBAction)onSwitchChange:(id)sender { // 啟動時顯示進度控件,停止時隱藏控件 BOOL bHide = !_switchDownload.isOn; [_sliderDownload setHidden:bHide]; [_activityIndicatorDownload setHidden:bHide]; [_processViewDownload setHidden:bHide]; if(_switchDownload.isOn) { _sliderDownload.value = 0; _sliderDownload.minimumValue = 0; _sliderDownload.maximumValue = arc4random()%1000 + 10; _textInfo.text = @"strat download ....."; _timerDownload = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(onDownload) userInfo:nil repeats:YES]; [_activityIndicatorDownload startAnimating]; _processViewDownload.progress = 0; } else { [_timerDownload invalidate]; [_activityIndicatorDownload stopAnimating]; _textInfo.text = @"Download finished."; } } -(IBAction)onDownload { _processViewDownload.progress += arc4random()%100 / 1000.0f; _sliderDownload.value = _processViewDownload.progress * _sliderDownload.maximumValue; _textInfo.text = [NSString stringWithFormat:@"%.2f%% %.2fM %.2fM", _processViewDownload.progress*100, _sliderDownload.value, _sliderDownload.maximumValue]; if(_processViewDownload.progress >= 1) { [_switchDownload setOn:NO animated:YES]; [self onSwitchChange:_switchDownload]; } }


代碼鏈接

生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 男人午夜免费视频 | 亚洲精品www久久久久久久软件 | 亚洲日本视频在线观看 | 亚洲国产高清视频在线观看 | 美美女高清毛片视频黄的一免费 | 国产免费一级精品视频 | 日韩三级免费 | 精品偷自拍另类在线观看 | 午夜小视频网站 | 最近最好的中文字幕免费 | 午夜影院免费入口 | 中文乱码视亚洲 | 国产综合在线观看 | 伊人亚洲 | 福利午夜影院 | 日韩精品久久久久久 | 老年人一级特黄aa大片 | 欧美理论片在线观看一区二区 | 范冰冰一级做a爰片久久毛片 | 久久厕所精品国产精品亚洲 | 欧美一级日韩在线观看 | 日韩精品一区二区三区中文在线 | 美女网站视频免费 | 亚洲不卡视频在线观看 | 伊人网在线免费观看 | 国产精品免费视频一区二区 | 一级毛片在线免费观看 | 激情影院在线视频永久观看 | 亚洲精品久久久久久久无 | 国产一区二区视频在线观看 | aⅴ天堂网 | 国产中文字幕在线免费观看 | 男人午夜 | 伊人久久大香线蕉精品哪里 | 欧美午夜色大片在线观看免费 | japanese日本护士xxx爽 | 伊人久久大香线蕉免费视频 | 中文字幕第页 | 久久久久亚洲精品一区二区三区 | 91四虎国自产在线播放线 | 欧美人与禽xoxo性伦交 |