This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @implementation UIView (Badge) | |
| - (void)addBadgeValue:(NSString *)badgeValue { | |
| [self removeBadgeValue]; | |
| UITabBar *tabBar = [[UITabBar alloc] initWithFrame:CGRectMake(0, 0, 320, 50)]; | |
| UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:@"" image:nil tag:0]; | |
| item.badgeValue = badgeValue; | |
| NSArray *array = [[NSArray alloc] initWithObjects:item, nil]; | |
| tabBar.items = array; | |
| [item release]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //判断当前网络类型 | |
| //Reachability.m 中 networkStatusForFlags 方法重构 | |
| - (NetworkStatus) networkStatusForFlags: (SCNetworkReachabilityFlags) flags | |
| { | |
| if ((flags & kSCNetworkReachabilityFlagsReachable) == 0) | |
| { | |
| return NotReachable; | |
| } | |
| BOOL retVal = NotReachable; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //把view截图为UIImage | |
| - (UIImage *)renderInImage:(UIView *)view | |
| { | |
| UIGraphicsBeginImageContext(view.bounds.size); | |
| [view.layer renderInContext:UIGraphicsGetCurrentContext()]; | |
| UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); | |
| UIGraphicsEndImageContext(); | |
| return (img); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import <UIKit/UIKit.h> | |
| @interface UIColor(ColorComponents) | |
| - (CGColorSpaceModel) colorSpaceModel; | |
| - (CGFloat) red; | |
| - (CGFloat) green; | |
| - (CGFloat) blue; | |
| - (CGFloat) alpha; | |
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //数字加千位分隔符 | |
| NSNumber *testNumber = [NSNumber numberWithFloat:0.01f]; | |
| NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; | |
| [numberFormatter setPositiveFormat:@"###,##0.00;"]; | |
| NSString *formattedNumberString = [numberFormatter stringFromNumber:testNumber]; | |
| NSLog(@"formattedNumberString:%@", formattedNumberString); | |
| //formattedNumberString log为1,234,567.89 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @interface NSDate(Conversion) | |
| + (NSDate *)dateFromString:(NSString *)dateString dateFormat:(NSString *)format; | |
| + (NSString *)stringFromDate:(NSDate *)date dateFormat:(NSString *)format; | |
| + (NSInteger)timeBetweenFrom:(NSDate*)fromDateTime | |
| to:(NSDate*)toDateTime | |
| withUnit:(NSCalendarUnit)unit; | |
| @end | |
| @implementation NSDate(Conversion) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //函数描述: string 字数限制 | |
| //输入参数:string:要判断的string ;minSize:最小字数限制;maxSize:最大字数限制 | |
| //返回值: BOOL:是否超出限制 | |
| //备注:一个汉字占两个字符,其他字母占一个字符 | |
| + (BOOL)checkStringSize:(NSString*)string minSize:(int)minSize maxSize:(int)maxSize | |
| { | |
| NSString *regex = @"^[\u4e00-\u9fa5]"; | |
| int length=[string length]; | |
| int currentStringSize=0; | |
| for (int i=0;i<length;i++) {//逐步判断string中的每个字符是否为汉字,是,占两个字符,不是,占一个字符 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| G: 公元时代,例如AD公元 | |
| yy: 年的后2位 | |
| yyyy: 完整年 | |
| MM: 月,显示为1-12 | |
| MMM: 月,显示为英文月份简写,如 Jan | |
| MMMM: 月,显示为英文月份全称,如 Janualy | |
| dd: 日,2位数表示,如02 | |
| d: 日,1-2位显示,如 2 | |
| EEE: 简写星期几,如Sun | |
| EEEE: 全写星期几,如Sunday |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - (void)savePicturefromurl:(NSString *)url path:(NSString *)path imgName:(NSString *)imgName | |
| { | |
| UIImage *img=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:url]]]; | |
| if(path==nil) | |
| { | |
| path = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:imgName]; | |
| } | |
| [UIImagePNGRepresentation(image) writeToFile:path atomically:YES]; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| NSMutableArray *someObject = [NSMutableArray array]; | |
| NSLog(@"%s:%d someObject=%@", __func__, __LINE__, someObject); | |
| [someObject addObject:@"foo"]; | |
| NSLog(@"%s:%d someObject=%@", __func__, __LINE__, someObject); |