Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,451 changes: 742 additions & 709 deletions MobileProject.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,12 @@
- (NSArray*)pinyinInitialsArray;
- (NSString*)pinyinInitialsString;


/**
* 正则验证-是否为中文
*
* @return return value description
*/
- (BOOL)isChinese;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,11 @@ - (NSString*)pinyinInitialsString{
return pinyin;
}

- (BOOL)isChinese
{
NSString *match=@"(^[\u4e00-\u9fa5]+$)";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF matches %@", match];
return [predicate evaluateWithObject:self];
}

@end
27 changes: 27 additions & 0 deletions MobileProject/Expand/Category/UIKit/UIImage/UIImage+QR.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// UIImage+QR.h
// MobileProject
//
// Created by 韩学鹏 on 16/6/17.
// Copyright © 2016年 wujunyang. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface UIImage (QR)


/**
* 使用字符串生成二维码
*
* @param qrString 需要生成二维码的字符串
* @param size 图片尺寸
* @param red red description
* @param green green description
* @param blue blue description
*
* @return return value description
*/
+ (UIImage *)qrCodeImageWithString:(NSString *)qrString withSize:(CGFloat)size withRed:(CGFloat)red andGreen:(CGFloat)green andBlue:(CGFloat)blue;

@end
94 changes: 94 additions & 0 deletions MobileProject/Expand/Category/UIKit/UIImage/UIImage+QR.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
//
// UIImage+QR.m
// MobileProject
//
// Created by 韩学鹏 on 16/6/17.
// Copyright © 2016年 wujunyang. All rights reserved.
//

#import "UIImage+QR.h"

@implementation UIImage (QR)

+ (UIImage *)qrCodeImageWithString:(NSString *)qrString withSize:(CGFloat)size withRed:(CGFloat)red andGreen:(CGFloat)green andBlue:(CGFloat)blue
{
CIImage *ciimage = [self ciimageWithString:qrString];
UIImage *qrImage = [self createNonInterpolatedUIImageFormCIImage:ciimage withSize:size];
qrImage = [self imageBlackToTransparent:qrImage withRed:red andGreen:green andBlue:blue];
return qrImage;
}

+ (CIImage *)ciimageWithString:(NSString *)qrString
{
NSData *stringData = [qrString dataUsingEncoding:NSUTF8StringEncoding];
//创建filter
CIFilter *qrFilter = [CIFilter filterWithName:@"CIQRCodeGenerator"];
//设置内容和纠错级别
[qrFilter setValue:stringData forKey:@"inputMessage"];
[qrFilter setValue:@"M" forKey:@"inputCorrectionLevel"];
//返回CIImage
return qrFilter.outputImage;
}

+ (UIImage *)createNonInterpolatedUIImageFormCIImage:(CIImage *)image withSize:(CGFloat) size {
CGRect extent = CGRectIntegral(image.extent);
CGFloat scale = MIN(size/CGRectGetWidth(extent), size/CGRectGetHeight(extent));
// 创建bitmap;
size_t width = CGRectGetWidth(extent) * scale;
size_t height = CGRectGetHeight(extent) * scale;
CGColorSpaceRef cs = CGColorSpaceCreateDeviceGray();
CGContextRef bitmapRef = CGBitmapContextCreate(nil, width, height, 8, 0, cs, (CGBitmapInfo)kCGImageAlphaNone);
CIContext *context = [CIContext contextWithOptions:nil];
CGImageRef bitmapImage = [context createCGImage:image fromRect:extent];
CGContextSetInterpolationQuality(bitmapRef, kCGInterpolationNone);
CGContextScaleCTM(bitmapRef, scale, scale);
CGContextDrawImage(bitmapRef, extent, bitmapImage);
// 保存bitmap到图片
CGImageRef scaledImage = CGBitmapContextCreateImage(bitmapRef);
CGContextRelease(bitmapRef);
CGImageRelease(bitmapImage);
return [UIImage imageWithCGImage:scaledImage];
}

void ProviderReleaseData (void *info, const void *data, size_t size){
free((void*)data);
}
+ (UIImage*)imageBlackToTransparent:(UIImage*)image withRed:(CGFloat)red andGreen:(CGFloat)green andBlue:(CGFloat)blue{
const int imageWidth = image.size.width;
const int imageHeight = image.size.height;
size_t bytesPerRow = imageWidth * 4;
uint32_t* rgbImageBuf = (uint32_t*)malloc(bytesPerRow * imageHeight);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(rgbImageBuf, imageWidth, imageHeight, 8, bytesPerRow, colorSpace,
kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipLast);
CGContextDrawImage(context, CGRectMake(0, 0, imageWidth, imageHeight), image.CGImage);
// 遍历像素
int pixelNum = imageWidth * imageHeight;
uint32_t* pCurPtr = rgbImageBuf;
for (int i = 0; i < pixelNum; i++, pCurPtr++){
if ((*pCurPtr & 0xFFFFFF00) < 0x99999900){
// change color
uint8_t* ptr = (uint8_t*)pCurPtr;
ptr[3] = red; //0~255
ptr[2] = green;
ptr[1] = blue;
}else{
uint8_t* ptr = (uint8_t*)pCurPtr;
ptr[0] = 0;
}
}
// 输出图片
CGDataProviderRef dataProvider = CGDataProviderCreateWithData(NULL, rgbImageBuf, bytesPerRow * imageHeight, ProviderReleaseData);
CGImageRef imageRef = CGImageCreate(imageWidth, imageHeight, 8, 32, bytesPerRow, colorSpace,
kCGImageAlphaLast | kCGBitmapByteOrder32Little, dataProvider,
NULL, true, kCGRenderingIntentDefault);
CGDataProviderRelease(dataProvider);
UIImage* resultUIImage = [UIImage imageWithCGImage:imageRef];
// 清理空间
CGImageRelease(imageRef);
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
return resultUIImage;
}

@end
39 changes: 39 additions & 0 deletions MobileProject/Expand/Tool/CheckBankCard/MPCheckBankCard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// MPCheckBankCard.h
// MobileProject
//
// Created by 韩学鹏 on 16/6/17.
// Copyright © 2016年 wujunyang. All rights reserved.
//
/*
当你输入信用卡号码的时候,有没有担心输错了而造成损失呢?其实可以不必这么担心,
因为并不是一个随便的信用卡号码都是合法的,它必须通过Luhn算法来验证通过。
该校验的过程:
1、从卡号最后一位数字开始,逆向将奇数位(1、3、5等等)相加。
2、从卡号最后一位数字开始,逆向将偶数位数字,先乘以2(如果乘积为两位数,则将其减去9),再求和。
3、将奇数位总和加上偶数位总和,结果应该可以被10整除。
例如,卡号是:5432123456788881
则奇数、偶数位(用红色标出)分布:5432123456788881
奇数位和=35
偶数位乘以2(有些要减去9)的结果:1 6 2 6 1 5 7 7,求和=35。
最后35+35=70 可以被10整除,认定校验通过。
请编写一个程序,从键盘输入卡号,然后判断是否校验通过。通过显示:“成功”,否则显示“失败”。
比如,用户输入:356827027232780
程序输出:成功
*/

#import <Foundation/Foundation.h>



@interface MPCheckBankCard : NSObject

/**
* 校验银行卡卡号
*
* @param cardId
* @return
*/
+ (BOOL)checkBankCard:(NSString *)cardId;

@end
71 changes: 71 additions & 0 deletions MobileProject/Expand/Tool/CheckBankCard/MPCheckBankCard.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//
// MPCheckBankCard.m
// MobileProject
//
// Created by 韩学鹏 on 16/6/17.
// Copyright © 2016年 wujunyang. All rights reserved.
//

#import "MPCheckBankCard.h"

@implementation MPCheckBankCard

+ (BOOL)checkBankCard:(NSString *)cardId
{
cardId = [cardId stringByReplacingOccurrencesOfString:@" " withString:@""];

//位数校验
if (cardId.length == 16 || cardId.length == 19) {

} else {
return NO;
}

char bit = [self getBankCardCheckCode:[cardId substringToIndex:cardId.length - 1]];
if (bit == 'N') {
return NO;
} else {
return [cardId characterAtIndex:cardId.length - 1] == bit;
}
}

+ (char)getBankCardCheckCode:(NSString *)nonCheckCodeCardId
{
if (nonCheckCodeCardId == nil || [self isEmptyString:nonCheckCodeCardId] || ![self isNo:nonCheckCodeCardId]) {
return 'N';
}
const char *chs = [nonCheckCodeCardId stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]].UTF8String;
int luhmSum = 0;
for (int i = (int)strlen(chs) - 1, j = 0; i >= 0; i--, j++) {
int k = chs[i] - '0';
if (j % 2 == 0) {
k *= 2;
k = k / 10 + k % 10;
}
luhmSum += k;
}
return (luhmSum % 10 == 0) ? '0' : (char) ((10 - luhmSum % 10) + '0');
}

+ (BOOL)isNo:(NSString *)no
{
NSString *carRegex = @"\\d+";
NSPredicate *carTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",carRegex];
return [carTest evaluateWithObject:no];
}

+ (BOOL)isEmptyString:(NSString *)str
{
if (str == nil || str == NULL) {
return YES;
}
if ([str isKindOfClass:[NSNull class]]) {
return YES;
}
if ([[str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length] == 0) {
return YES;
}
return NO;
}

@end
89 changes: 89 additions & 0 deletions MobileProject/Expand/Tool/OtherHelper/MPUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
//
// MAUtils.h
// MobileProject
//
// Created by 韩学鹏 on 16/6/17.
// Copyright © 2016年 wujunyang. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface MPUtils : NSObject

/**
* 拨打电话
*
* @param phone 电话号码
*/
+ (void)callWithPhoneNumber:(NSString *)phone;


/**
* 屏幕上显示一个消息,需要调用hideMessage隐藏
*
* @param msg 提示信息
*/
+ (void)showMessage:(NSString *)msg;

/**
* 隐藏屏幕上的消息
*/
+ (void)hideMessage;

/**
* 显示一个信息在指定时间后删除
*
* @param msg 提示信息
* @param delay 消失时间
*/
+ (void)showToast:(NSString *)msg delay:(NSUInteger)delay;

#pragma mark - 邮箱、手机等是否有效验证.

/**
* 邮箱验证
*
* @param email email description
*
* @return return value description
*/
+ (BOOL)isValidateEmail:(NSString *)email;

/**
* 手机号码验证
*
* @param mobile mobile description
*
* @return return value description
*/
+ (BOOL)isValidateMobile:(NSString *)mobile;

/**
* 身份证号码验证
*
* @param identityCard identityCard description
*
* @return return value description
*/
+ (BOOL)isValidateIDCard:(NSString *)identityCard;

/**
* 车牌号验证
*
* @param carNo carNo description
*
* @return return value description
*/
+ (BOOL)isValidateCarNo:(NSString *)carNo;


/**
* 是否为空字符串
*
* @param str str description
*
* @return return value description
*/
+ (BOOL)isEmptyString:(NSString *)str;

@end
Loading