#import "BaseViewController.h"
#import "MBProgressHUD.h"
@interface BaseViewController ()
@end
@implementation BaseViewController
{
UIActivityIndicatorView *_proView;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.edgesForExtendedLayout = UIRectEdgeNone;
self.view.backgroundColor = [UIColor whiteColor];
}
-(void)showProgressView:(UIView *)superView{
if(_proView!=nil)
{
[_proView stopAnimating];
_proView = nil;
}
_proView = [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(0, 0, 80, 80)];
_proView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
[_proView setCenter:superView.center];
_proView.backgroundColor=[UIColor grayColor];
_proView.alpha = 0.8;
_proView.layer.cornerRadius = 8;
_proView.layer.masksToBounds = YES;
[superView addSubview:_proView];
[_proView startAnimating];
}
-(void)hideProgressView{
if(_proView!=nil){
[_proView stopAnimating];
_proView = nil;
}
}
-(void)showSmallProgressView:(UIView *)superView
{
UIActivityIndicatorView *indicator=[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
indicator.frame=CGRectMake(0, 0, 40, 40);
indicator.center=CGPointMake(superView.bounds.size.width/2, superView.bounds.size.height/2);
indicator.tag=10001;
[superView addSubview:indicator];
[indicator startAnimating];
}
-(void)hideSmallProgressView:(UIView *)superView
{
//两个方案
//1.提示器对象作为baseViewController成员变量,保证这个变量只有一个
//2.活动提示器设置tag,用tag从superView找到活动提示器隐藏
[[superView viewWithTag:10001]removeFromSuperview];
}
-(BOOL)shouldAutorotate{
return YES;
}
//支持竖屏
-(UIInterfaceOrientationMask)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}
/*时间差,相差分钟*/
- (BOOL)intervalSinceNow: (NSDate *) lastDate
{
NSTimeInterval late=[lastDate timeIntervalSince1970]*1;
NSDate *date = [NSDate date];
NSTimeZone *zone = [NSTimeZone systemTimeZone];
NSInteger interval = [zone secondsFromGMTForDate: date];
NSDate *dat = [date dateByAddingTimeInterval: interval];
NSTimeInterval now=[dat timeIntervalSince1970]*1;
NSTimeInterval cha=now-late;
// if (cha/3600<1)
// {
// timeString = [NSString stringWithFormat:@"%f", cha/86400];
// timeString = [timeString substringToIndex:timeString.length-7];
// return [timeString intValue];
// }
// return -1;
if(cha>60*60*3)
{
return true;
}
else
{
return false;
}
}
/**
* 纯文本方式显示提示文字, 显示3秒后自动消失
*
* @param alertMsg 提示内容
*/
- (void)showAlert:(NSString*)alertMsg
{
//如果提示器未隐藏, 则先隐藏提示器
if (![self.myHud isHidden]) {
[self.myHud hideAnimated:YES];
self.myHud = nil;
}
//显示提示器
self.myHud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].delegate.window animated:YES];
//显示纯文本方式
self.myHud.mode = MBProgressHUDModeText;
self.myHud.bezelView.color = [UIColor blackColor];
self.myHud.label.text = alertMsg;
self.myHud.label.textColor = [UIColor whiteColor];
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 2.5 * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void) {
// Do something...
[self.myHud hideAnimated:YES];
});
}
/*分割时间*/
-(NSDateComponents *)getDateComponents
{
NSDate *date = [NSDate date];
NSCalendar *gregorian=[[NSCalendar alloc]initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
unsigned unitFlags=NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay|NSCalendarUnitHour|NSCalendarUnitMinute|NSCalendarUnitSecond;
NSDateComponents *comp=[gregorian components:unitFlags fromDate:date];
return comp;
}
#pragma mark 判断电话号码是否合法 正则表达式
/*手机号码验证 MODIFIED BY HELENSONG*/
- (BOOL)isMobileNumber:(NSString *)mobileNum {
NSString *MOBILE = @"^1(3[0-9]|5[0-35-9]|8[025-9])\\d{8}$";
/**
10 * 中国移动:China Mobile
11 * 134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188
12 */
NSString *CM = @"^1(34[0-8]|(3[5-9]|5[017-9]|8[2378])\\d)\\d{7}$";
/**
15 * 中国联通:China Unicom
16 * 130,131,132,152,155,156,185,186
17 */
NSString *CU = @"^1(3[0-2]|5[256]|8[56])\\d{8}$";
/**
20 * 中国电信:China Telecom
21 * 133,1349,153,180,181,189
22 */
NSString *CT = @"^1((33|53|8[019])[0-9]|349)\\d{7}$";
/**
25 * 大陆地区固话及小灵通
26 * 区号:010,020,021,022,023,024,025,027,028,029
27 * 号码:七位或八位
28 */
// NSString * PHS = @"^0(10|2[0-5789]|\\d{3})\\d{7,8}$";
NSPredicate *regextestmobile =
[NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];
NSPredicate *regextestcm =
[NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM];
NSPredicate *regextestcu =
[NSPredicate predicateWithFormat:@"SELF MATCHES %@", CU];
NSPredicate *regextestct =
[NSPredicate predicateWithFormat:@"SELF MATCHES %@", CT];
if (([regextestmobile evaluateWithObject:mobileNum] == YES) ||
([regextestcm evaluateWithObject:mobileNum] == YES) ||
([regextestct evaluateWithObject:mobileNum] == YES) ||
([regextestcu evaluateWithObject:mobileNum] == YES)) {
return YES;
} else {
return NO;
}
}
//将日期格式化成字符串
-(NSString *)getDateString:(NSDate *)date
{
NSDateFormatter* dateFormat = [[NSDateFormatter alloc] init];//实例化一个NSDateFormatter对象
[dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];//设定时间格式,要注意跟下面的dateString匹配,否则日起将无效
NSString *dateStr =[dateFormat stringFromDate:date];
return dateStr;
}
@end