开发中最有用关键代的码合集.docxVIP

  • 3
  • 0
  • 约1.43万字
  • 约 16页
  • 2017-02-08 发布于北京
  • 举报
开发中最有用关键代的码合集

iOS开发中最有用关键的代码合集本文整理了,在iOS开发中我们所遇到一些开发问题的技巧类的代码,让你在开发过程中避免了很多弯路,希望能给你的开发带来帮助和启发。1.判断邮箱格式是否正确的代码:?//?利用正则表达式验证?-(?BOOL?)isValidateEmail:(?NSString?*)email??{??NSString??*emailRegex?=??@[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}?;??NSPredicate??*emailTest?=?[?NSPredicate???predicateWithFormat?:?@SELF?MATCHES%@?,emailRegex];??return?[emailTest?evaluateWithObject?:email];??}??2.图片压缩?用法:?UIImage?*yourImage=?[self?imageWithImageSimple:image?scaledToSize:CGSizeMake(210.0,?210.0)];?//?压缩图片?-?(?UIImage?*)imageWithImageSimple:(?UIImage?*)image?scaledToSize:(?CGSize?)newSize??{??//?Create?a?graphics?image?context?UIGraphicsBeginImageContext?(newSize);??//?Tell?the?old?image?to?draw?in?this?newcontext,?with?the?desired?//?new?size?[image??drawInRect?:?CGRectMake?(?0?,?0?,newSize.?width?,newSize.?height?)];??//?Get?the?new?image?from?the?context?UIImage?*?newImage?=??UIGraphicsGetImageFromCurrentImageContext?();??//?End?the?context?UIGraphicsEndImageContext?();??//?Return?the?new?image.?return??newImage;??}???3.亲测可用的图片上传代码?-?(?IBAction?)uploadButton:(?id?)sender?{??UIImage?*image?=?[?UIImage?imageNamed?:?@1.jpg?];?//?图片名?NSData??*imageData?=??UIImageJPEGRepresentation?(image,?0.5?);//?压缩比例?NSLog?(?@?字节数?:%i?,[imageData?length]);??//?post?url?NSString??*urlString?=??@13:8090/text/UploadServlet?;??//?服务器地址?//?setting?up?the?request?object?now?NSMutableURLRequest??*request?=?[[?NSMutableURLRequest???alloc?]??init?]?;??[request??setURL?:[?NSURLURLWithString?:urlString]];??[request??setHTTPMethod?:?@POST?];??//?NSString?*boundary?=?[?NSString?stringWithString?:?@---------------------------14737809831466499882746641449?];??NSString??*contentType?=?[?NSString???stringWithFormat?:?@multipart/form-data;boundary=%@?,boundary];??[request??addValue?:contentType??forHTTPHeaderField?:??@Content-Type?];??//?NSMutableData?*body?=?[?NSMutableData?data?];??[body??appendData?:[[?NSString?stringWithFormat?:?@\r\n--%@\r\n?,boundary]??dataUsingEncoding?:?NSUTF8StringEncoding?]];??[body??appendD

文档评论(0)

1亿VIP精品文档

相关文档