项目中的工具类
项目中我们一般需要新建一个工具类,用来实现一些项目中经常使用的功能,方便复用,这边我收集了一些自己经常使用的功能
1.添加文字提示框
+(void)showHubTipWithString:(NSString *)string offsetY:(CGFloat)y{ if (string && string.length > 0) { dispatch_async(dispatch_get_main_queue(), ^{ MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[[UIApplication sharedApplication] keyWindow] animated:YES]; hud.mode = MBProgressHUDModeText; hud.detailsLabel.font = [UIFont boldSystemFontOfSize:17.0]; hud.detailsLabel.text =string; hud.margin = 20.f; hud.offset=SPPoint(0, y); hud.removeFromSuperViewOnHide = YES; [hud hideAnimated:YES afterDelay:0.8]; }); } }
2.添加加载提示框
+(MBProgressHUD*)showLoadingHubAddedTo:(UIView*)view{ MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:view]; hud.contentColor=[UIColor whiteColor]; hud.bezelView.backgroundColor=[UIColor colorWithWhite:0.1 alpha:1]; hud.mode = MBProgressHUDModeIndeterminate; hud.detailsLabel.font=SPFont(17); hud.minShowTime=2; hud.userInteractionEnabled = YES; hud.removeFromSuperViewOnHide = YES; [view addSubview:hud]; return hud; }
3.手机号验证
+(BOOL)validateMobile:(NSString*)mobile{ NSString*mobileRegex=@"^(1[123456789][0-9]{9}$)"; NSPredicate*mobileTest=[NSPredicate predicateWithFormat:@"SELF MATCHES %@",mobileRegex]; return [mobileTest evaluateWithObject:mobile]; }
4.密码验证
+(BOOL)validatePassword:(NSString*)password{ NSString*passwordRegex=@"^([a-zA-Z0-9]{6,12}$)"; NSPredicate*passwordTest=[NSPredicate predicateWithFormat:@"SELF MATCHES %@",passwordRegex]; return [passwordTest evaluateWithObject:password]; }
5.获取段落行高
+(CGFloat)GetCellHeightWithString:(NSString *)string width:(CGFloat)width attributes:(NSDictionary *)attributes{ CGRect sizestring = [string boundingRectWithSize:CGSizeMake(width,MAXFLOAT) options: NSStringDrawingUsesLineFragmentOrigin| NSStringDrawingUsesFontLeading attributes:attributes context:nil]; return ceil(sizestring.size.height); }
6.秒数到时间到转化
+(NSString*)changeNumberToTime:(NSInteger)number{ NSString*minute=[NSString stringWithFormat:@"%02ld",number%3600/60]; NSString*second=[NSString stringWithFormat:@"%02ld",number%60]; return [NSString stringWithFormat:@"%@:%@",minute,second]; }
« yum常用命令
|
js获取视频或者音频时长»