美文网首页
这几年项目开发中的小程序片段整理

这几年项目开发中的小程序片段整理

作者: 烟雨平生花飞舞 | 来源:发表于2017-11-22 14:47 被阅读0次

1、cell的几种创建方式:

2、判断webview是否加载完成:

- (void)webViewDidFinishLoad:(UIWebView *)webView

{

//在此处改变headerview的高度

// js获取高度

self.scrollHeight = [[webView stringByEvaluatingJavaScriptFromString: @"document.body.scrollHeight"] floatValue];

if (!webView.isLoading) {

NSString *readyState = [webView stringByEvaluatingJavaScriptFromString:@"document.readyState"];

BOOL complete = [readyState isEqualToString:@"complete"];

if (complete) {

self.isLoadFinish = YES;

}

}

}

3、webview滚动截图:

- (UIImage *)screenShotWithScrollView:(UIScrollView *)scrollView

{

UIImage* image;

UIGraphicsBeginImageContextWithOptions(scrollView.contentSize, NO, [UIScreen mainScreen].scale);

{

CGPoint savedContentOffset = scrollView.contentOffset;

CGRect savedFrame = scrollView.frame;

scrollView.contentOffset = CGPointZero;

scrollView.frame = CGRectMake(0, 0, scrollView.contentSize.width, scrollView.contentSize.height);

[scrollView.layer renderInContext: UIGraphicsGetCurrentContext()];

image = UIGraphicsGetImageFromCurrentImageContext();

scrollView.contentOffset = savedContentOffset;

scrollView.frame = savedFrame;

}

UIGraphicsEndImageContext();

NSData *data = UIImageJPEGRepresentation(image, [UIScreen mainScreen].scale);

[data writeToFile:[self getPathWithDocument:@"protocol" fileName:@"protocol.png"] atomically:NO];

if (image != nil)

{

return image;

}

return nil;

}

- (NSString *)getPathWithDocument:(NSString *)document fileName:(NSString *)name

{

NSString *path = [NSString stringWithFormat:@"Documents/%@",document];

NSString *fileName = [NSString stringWithFormat:@"%@",name];

path = [NSString getFilePathWithDir:path fileName:fileName];

NSLog(@"path == %@",path);

return path;

}

+ (NSString *)getFilePath:(NSString *)aPath

{

return [NSHomeDirectory() stringByAppendingPathComponent:aPath];

}

+ (NSString *)getFilePathWithDir:(NSString *)aDir fileName:(NSString *)aName

{

NSString *path = [self getFilePath:aDir];

NSFileManager *manager = [NSFileManager defaultManager];

if (![manager fileExistsAtPath:path]) {

[manager createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil];

}

return [path stringByAppendingPathComponent:aName];

}

4、图片合成:

//获得某个范围内的屏幕图像

- (UIImage *)imageFromView:(UIView *)theView atFrame:(CGRect)r

{

UIGraphicsBeginImageContext(CGSizeMake(theView.width, _signatureView.bottom));

CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSaveGState(context);

UIRectClip(r);

[theView.layer renderInContext:context];

UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return  theImage;

}

- (UIImage *)combine:(UIImage *)topImage bottomImage:(UIImage *)bottomImg imageSacle:(CGFloat)scale

{

CGFloat height = topImage.size.height + bottomImg.size.height;

CGSize offScreenSize = CGSizeMake(self.view.width, height);

UIGraphicsBeginImageContextWithOptions(offScreenSize, YES, scale);

CGRect rect = CGRectMake(0, 0, self.view.width, topImage.size.height);

[topImage drawInRect:rect];

rect.origin.y+=topImage.size.height;

CGRect rect1 = CGRectMake(0, rect.origin.y, self.view.width, bottomImg.size.height);

[bottomImg drawInRect:rect1];

UIImage *imagez = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

NSData *data = UIImageJPEGRepresentation(imagez, 0.5);

[data writeToFile:[self getPathWithDocument:@"protocol" fileName:@"protocolSignature.png"] atomically:NO];

return imagez;

}

5、

相关文章

  • 这几年项目开发中的小程序片段整理

    1、cell的几种创建方式: 2、判断webview是否加载完成: - (void)webViewDidFinis...

  • 微信小程序1

    小程序官方: 小程序开发文档: 微信开发社区: WePY命令行工具 在开发目录中生成Demo开发项目 切换至项目目...

  • 2-1 开篇介绍 以及下载工具

    小程序开发环境 下载微信web开发工具 小程序目前的情况 没有小程序号的限制 新建小程序项目 微信web开发者工具...

  • 小程序提交了!

    从零开发一款小程序项目——生活全能通!主要学习小程序的整个开发流程、学习小程序组件和API的使用。本项目仅用于学习...

  • 小程序开发整理

    本文将基于笔者浅薄的经验总结和整理一个基本小程序的从零开发到上线流程。从编码上讲小程序的开发非常简单,不过这是相对...

  • 小程序开发整理

    该文档为开发过程中遇到的一些问题以及一些好用的平台,持续更新以及整理中。。。 小程序客服 小程序接收消息和事件 服...

  • 《微信小程序开发从入门到实战》学习十二

    第三章 开发第一个小程序 3.2 开发投票小程序的首页 3.2.1 小程序的初始配置 在微信开发工具创建小程序项目...

  • 微信小程序开发基础知识

    vscode配置 vscode开发微信小程序安装的插件: wechat-snippet微信小程序代码辅助,代码片段...

  • 2018-12-17

    微信小程序案例最全整理 本文整理了微信小程序开发当中的一些开源Demo,供开发者学习研究,适合入门以及初学开发者 ...

  • 微信小程序开发手记和大众点评实战系列

    新手向!微信小程序开发手记系列: 微信小程序开发手记《一》:项目的代码结构微信小程序开发手记《二》:属性displ...

网友评论

      本文标题:这几年项目开发中的小程序片段整理

      本文链接:https://www.haomeiwen.com/subject/zmonvxtx.html