本文共 3411 字,大约阅读时间需要 11 分钟。
这个第三方和MBProgressHUD差不多,也挺简单的。
//// ViewController.m// ProgressHUD//// Created by City--Online on 15/6/15.// Copyright (c) 2015年 City--Online. All rights reserved.//#import "ViewController.h"#import "SVProgressHUD.h"@interface ViewController ()@end@implementation ViewController- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:SVProgressHUDWillAppearNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:SVProgressHUDDidAppearNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:SVProgressHUDWillDisappearNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:SVProgressHUDDidDisappearNotification object:nil];}- (void)handleNotification:(NSNotification *)notif{ NSLog(@"Notification recieved: %@", notif.name); NSLog(@"Status user info key: %@", [notif.userInfo objectForKey:SVProgressHUDStatusUserInfoKey]);}- (void)viewDidLoad { [super viewDidLoad]; UIButton *btn=[UIButton buttonWithType:UIButtonTypeSystem]; [btn setTitle:@"提示框" forState:UIControlStateNormal]; btn.frame=CGRectMake(20, 100, 100, 100); [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:btn];}-(void)btnClick:(id)sender{ // [SVProgressHUD showWithStatus:@"Loading"];// [SVProgressHUD show];// dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{// sleep(3);// dispatch_async(dispatch_get_main_queue(), ^{// [SVProgressHUD dismiss];// });// }); // [self showWithProgress]; [self showSuccess];}static float progress = 0.0f;- (void)showWithProgress { progress = 0.0f; [SVProgressHUD showProgress:0 status:@"Loading"]; [self performSelector:@selector(increaseProgress) withObject:nil afterDelay:0.3f];}- (void)increaseProgress { progress+=0.1f; [SVProgressHUD showProgress:progress status:@"Loading"]; if(progress < 1.0f) [self performSelector:@selector(increaseProgress) withObject:nil afterDelay:0.3f]; else [self performSelector:@selector(dismiss) withObject:nil afterDelay:0.4f];}- (void)dismiss { [SVProgressHUD dismiss];}- (void)showInfo{ [SVProgressHUD showInfoWithStatus:@"Useful Information."];}- (void)showSuccess { [SVProgressHUD showSuccessWithStatus:@"Great Success!"];}- (void)showError { [SVProgressHUD showErrorWithStatus:@"Failed with Error"];}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}@end
转载地址:http://ayxyx.baihongyu.com/