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
- (UIImage *) createImageWithColor: (UIColor *) color | |
{ | |
CGRect rect=CGRectMake(0.0f, 0.0f, 1.0f, 1.0f); | |
UIGraphicsBeginImageContext(rect.size); | |
CGContextRef context = UIGraphicsGetCurrentContext(); | |
CGContextSetFillColorWithColor(context, [color CGColor]); | |
CGContextFillRect(context, rect); | |
UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); |
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
// 正则验证 | |
NSError *error; | |
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"^1\\d{10}$" | |
options:NSRegularExpressionCaseInsensitive | |
error:&error]; | |
NSUInteger count = [regex numberOfMatchesInString:userPhone | |
options:NSRegularExpressionCaseInsensitive | |
range:NSMakeRange(0, [userPhone length])]; | |
// 格式验证失败 | |
if (count != 1) { |
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
+ (instancetype)sharedPlugin | |
{ | |
static id sharedPlugin = nil; | |
static dispatch_once_t onceToken; | |
dispatch_once(&onceToken, ^{ | |
sharedPlugin = [[self alloc] init]; | |
}); | |
return sharedPlugin; | |
} |
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
// 是否高清屏 | |
#define isRetina ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO) | |
// 是否iPad | |
#define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) | |
// 是否模拟器 | |
#define isSimulator (NSNotFound != [[[UIDevice currentDevice] model] rangeOfString:@"Simulator"].location) | |
// 是否iPhone5 | |
#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO) |
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
- (NSString *)URLEncodedString { | |
NSString *result = (NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)self, NULL, CFSTR("!*'();:@&=+$,/?%#[]"), kCFStringEncodingUTF8); | |
return [result autorelease]; | |
} | |
- (NSString *)URLDecodedString { | |
NSString *result = (NSString *)CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault, (CFStringRef)self, CFSTR(""), kCFStringEncodingUTF8); | |
return [result autorelease]; | |
} |
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
- (NSString *)md5 { | |
const char *cStr = [self UTF8String]; | |
unsigned char result[16] = {0}; | |
CC_MD5(cStr, strlen(cStr), result); | |
return [NSString stringWithFormat: | |
@"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X", | |
result[0], result[1], result[2], result[3], | |
result[4], result[5], result[6], result[7], | |
result[8], result[9], result[10], result[11], | |
result[12], result[13], result[14], result[15] |
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
// 如hex为0xEEEEEE | |
+ (UIColor *) colorWithHex:(int)hex { | |
return [UIColor colorWithRed:((float)((hex & 0xFF0000) >> 16))/255.0 | |
green:((float)((hex & 0xFF00) >> 8))/255.0 | |
blue:((float)(hex & 0xFF))/255.0 alpha:1.0]; | |
} | |
// hex为#EEEEEE | |
+ (UIColor *)colorWithHexString:(NSString *)stringToConvert { | |
NSString *cString = [[stringToConvert stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString]; |
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
- (NSString *)phonetic { | |
NSMutableString *source = [self mutableCopy]; | |
CFStringTransform((CFMutableStringRef)source, NULL, kCFStringTransformMandarinLatin, NO); | |
CFStringTransform((CFMutableStringRef)source, NULL, kCFStringTransformStripDiacritics, NO); | |
return [source autorelease]; | |
} |
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 <QuartzCore/QuartzCore.h> | |
@implementation UIView (RectCorner) | |
- (void)setCornerOnTop { | |
UIBezierPath *maskPath; | |
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds | |
byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight) | |
cornerRadii:CGSizeMake(8.0, 8.0)]; | |
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init]; | |
maskLayer.frame = self.bounds; | |
maskLayer.path = maskPath.CGPath; |
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 NSString (GetWeek) | |
- (NSString *)getWeek { | |
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; | |
dateFormatter.dateFormat = @"yyyy-MM-dd"; | |
NSDate *date = [dateFormatter dateFromString:self]; | |
[dateFormatter release]; | |
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; | |
NSInteger unitFlags = NSWeekdayCalendarUnit; | |
NSDateComponents *comps = [calendar components:unitFlags fromDate:date]; | |
[calendar release]; |
OlderNewer