Skip to content

Instantly share code, notes, and snippets.

// 正则验证
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) {
- (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();