| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- //
- // Util.m
- // IBOSS
- //
- // Created by iHope on 14-6-6.
- // Copyright (c) 2014年 elongtian. All rights reserved.
- //
- #import "Util.h"
- @implementation Util
- +(void)alignLabelWithTop:(UILabel *)label{
- CGSize maxSize = CGSizeMake(label.frame.size.width, 999);
- label.adjustsFontSizeToFitWidth = NO;
- CGSize actualSize = [label.text sizeWithFont:label.font constrainedToSize:maxSize lineBreakMode:label.lineBreakMode];
- CGRect rect = label.frame;
- rect.size.height = actualSize.height;
- label.frame = rect;
-
- }
- +(NSString*)objectToJson:(id)_obj{
- if (_obj==nil) {
- return @"";
- }
- NSError *parseError = nil;
- NSData *jsonData = [NSJSONSerialization dataWithJSONObject:_obj options:NSJSONWritingPrettyPrinted error:&parseError];
- return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
- }
- // 判断电话是否有效
- + (BOOL)isValidTelephone:(NSString *)telephone{
- /**
- * 手机号码
- * 移动:134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188,147
- * 联通:130,131,132,152,155,156,185,186
- * 电信:133,1349,153,180,181,189
- */
- NSString *mobile = @"^1(3[0-9]|5[0-35-9]|8[012345-9]|47|7[013678])\\d{8}$";
- /**
- * 大陆地区固话及小灵通 区号和电话之间没有-
- * 区号:010,020,021,022,023,024,025,027,028,029
- * 号码:七位或八位
- */
- NSString *phs = @"^0(10|2[0-5789]|\\d{3})\\d{7,8}$";
-
- NSPredicate *predicatemobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", mobile];
- NSPredicate *predicatephs = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", phs];
-
-
- return [predicatemobile evaluateWithObject:telephone] || [predicatephs evaluateWithObject:telephone];
- }
- /**
- 返回Home区域的高度
- @return <#return value description#>
- */
- + (CGFloat) obtainHomeAreaHeight{
- return (SCREENHEIGHT >= 812 ? 34 : 0);
- }
- + (NSString *)positiveFormat:(NSString *)text{
-
- if(!text || [text floatValue] == 0){
- return @"¥0.00";
- }else{
- NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
- [numberFormatter setPositiveFormat:@"¥,###.00;"];
- return [numberFormatter stringFromNumber:[NSNumber numberWithDouble:[text doubleValue]]];
- }
- return @"";
-
- }
- +(NSString*)thousandSeparatorFormat:(NSString *)number
- {
- if(!number || [number floatValue] == 0){
- return @"0.00";
- }else{
- NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
- [numberFormatter setPositiveFormat:@",###.00;"];
- return [numberFormatter stringFromNumber:[NSNumber numberWithDouble:[number doubleValue]]];
- }
- return @"";
- }
- @end
|