Some of the most commonly used tool classes in IOS projects

Source: Internet
Author: User
Tags sha1 encryption

#pragma mark Password SHA1 encryption

+ (NSString *) Sha1withinputstr: (NSString *) inputstr{

const char * CStr = [Inputstr cstringusingencoding:nsutf8stringencoding];

NSData * data = [NSData datawithbytes:cstr length:inputStr.length];

uint8_t Digest[cc_sha1_digest_length];

CC_SHA1 (data.bytes, (unsigned int) data.length, digest);

nsmutablestring * Outputstr = [nsmutablestring stringwithcapacity:cc_sha1_digest_length * 2];

for (int i = 0; i< cc_sha1_digest_length; i++) {

[Outputstr appendformat:@ "%02x", Digest[i]];

}

return outputstr;

}

#pragma mark is judging if the phone number is correct

+ (BOOL) ValidateNumber: (NSString *) textstring

{

nsstring* [email protected] "^1[3|4|5|7|8][0-9]\\d{8}$";

Nspredicate *numberpre = [Nspredicate predicatewithformat:@ "Self MATCHES%@", number];

return [Numberpre evaluatewithobject:textstring];

}

#pragma mark is judging the ID number.

+ (BOOL) Validateidentitycard: (NSString *) Identitycard

{

BOOL Flag;

if (identitycard.length <= 0) {

flag = NO;

return flag;

}

NSString *regex2 = @ "^ (\\d{14}|\\d{17}) (\\d|[ XX]) $ ";

Nspredicate *identitycardpredicate = [Nspredicate predicatewithformat:@ "Self MATCHES%@", Regex2];

return [Identitycardpredicate Evaluatewithobject:identitycard];

}

#pragma mark is judging the courier number

+ (BOOL) Validateemsnumber: (NSString *) emsnumber

{

BOOL Flag;

if (emsnumber.length <= 0) {

flag = NO;

return flag;

}

NSString * reg = @ "^[0-9a-za-z]{10,}$";

Nspredicate *identitycardpredicate = [Nspredicate predicatewithformat:@ "Self MATCHES%@", Reg];

return [Identitycardpredicate Evaluatewithobject:emsnumber];

}

#pragma mark is judging the amount of cash to be taken

+ (BOOL) Validatecashmoney: (NSString *) Cashmoney

{

BOOL Flag;

if (cashmoney.length <= 0) {

flag = NO;

return flag;

}

NSString * reg = @ "^ (([1-9]{1}\\d*) | ( [0] {1})) (\\. (\\d) {()})? $";

Nspredicate *identitycardpredicate = [Nspredicate predicatewithformat:@ "Self MATCHES%@", Reg];

return [Identitycardpredicate Evaluatewithobject:cashmoney];

}

#pragma mark-the integer multiples of the regular judgment 100

+ (BOOL) Judge100integertimes: (NSString *) str

{

NSString *remainderstr = [NSString stringwithformat:@ "%d", [str intvalue]% 100];

Nspredicate *numberpre = [Nspredicate predicatewithformat:@ "Self MATCHES%@", @ "^[0]$"];

return [Numberpre EVALUATEWITHOBJECT:REMAINDERSTR];

}

#pragma mark is determining if the login password is correct (6-20-digit alphanumeric combination)

+ (BOOL) Validatenumberorletter: (NSString *) textstring

{

BOOL result = false;

if ([textstring length] >= 6) {

NSString * regex = @ "^ (?! [0-9]+$) (?! [a-za-z]+$] [0-9a-za-z]{6,20}$];

Nspredicate *pred = [Nspredicate predicatewithformat:@ "Self MATCHES%@", regex];

result = [Pred evaluatewithobject:textstring];

}

return result;

}

#pragma mark is simply judging if the bank card number is correct (16-19 digits)

+ (BOOL) Validatebankcardnumber: (NSString *) textstring

{

nsstring* [email protected] "^ ([0-9]{16}|[ 0-9]{19}) $ ";

Nspredicate *numberpre = [Nspredicate predicatewithformat:@ "Self MATCHES%@", number];

return [Numberpre evaluatewithobject:textstring];

}

#pragma mark Mobile number in the middle of the change *

+ (NSString *) Cipherchangetext: (NSString *) Changetext Firstone: (nsinteger) Firstone Lenght: (nsinteger) lenght{

NSString * Number = [Changetext stringbyreplacingcharactersinrange:nsmakerange (Firstone, lenght) withString:@ "* * *"];

return number;

}

#pragma mark gets the phone UUID

+ (NSString *) uuid{

NSString * uuid = [[[Uidevice Currentdevice] Identifierforvendor] uuidstring];

return UUID;

}

#pragma mark Adaptive Height

+ (CGRect) Sizeoftext: (NSString *) Text width: (cgfloat) Width Font: (cgfloat) fontfloat{

Nsdictionary * Textdic = [nsdictionary dictionarywithobjectsandkeys:[uifont systemfontofsize:fontfloat], Nsfontattributename, nil];

CGRect rect = [Text boundingrectwithsize:cgsizemake (width, 0) options:nsstringdrawinguseslinefragmentorigin | Nsstringdrawingusesfontleading Attributes:textdic Context:nil];

return rect;

}

#pragma mark Adaptive width

+ (CGRect) Sizeoftext: (NSString *) Text height: (cgfloat) Height Font: (cgfloat) fontfloat{

Nsdictionary * Textdic = [nsdictionary dictionarywithobjectsandkeys:[uifont systemfontofsize:fontfloat], Nsfontattributename, nil];

CGRect rect = [text boundingrectwithsize:cgsizemake (0, height) options:nsstringdrawinguseslinefragmentorigin | Nsstringdrawingusesfontleading Attributes:textdic Context:nil];

return rect;

}

#pragma mark picture and more than compression

+ (CGFloat) Zoomimagescalewithimage: (UIImage *) image withwidth: (cgfloat) width

{

UIImage *newimage;

Determine if the size of the picture is larger than the width of the screen let it compress

if (Image.size.width > width) {

Start compressing pictures

Cgsize size = image.size;

Uigraphicsbeginimagecontext (Cgsizemake (width, Width * size.height/size.width));

[Image drawinrect:cgrectmake (0, 0, Width, Width * size.height/size.width)];

NewImage = Uigraphicsgetimagefromcurrentimagecontext ();

Uigraphicsendimagecontext ();

//    }

return newImage.size.height;

}

#pragma mark Create recycle keyboard icon

+ (void) Createrecivekeyboardtoolbarwithview: (ID) view{//Recycle keyboard

UIView * Aview = [[UIView alloc]initwithframe:cgrectmake (0, 0, Width_fullscreen, 30)];

Aview.backgroundcolor = nil;

Blockbutton * btn = [Blockbutton buttonwithtype:uibuttontypecustom];

Btn.frame = CGRectMake (width_fullscreen-35, 2, 30, 25);

[Btn setimage:[uiimage imagenamed:@ "Closekeyboard"] forstate:uicontrolstatenormal];

[Btn setblock:^ (Blockbutton * btn) {

[View Endediting:yes];

}];

[Aview ADDSUBVIEW:BTN];

[View Setinputaccessoryview:aview];

}

Some of the most common tool classes in IOS projects

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.