#import "ViewController.h"
#import "Masonry.h"
@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];//一般的view生成图片方法UIView *subview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame) - 0 * 2, CGRectGetHeight(self.view.frame) - 0 * 2)];[self.view addSubview:subview];
//    [self onUIImageSubViewWithView:subview];
//
//    UIGraphicsBeginImageContext(subview.bounds.size);
//    self.view.backgroundColor = [UIColor whiteColor];
//    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
//    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
//
    UIImageView *ig=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(subview.frame), CGRectGetHeight(subview.frame) )];ig.backgroundColor = [UIColor yellowColor];ig.image = [self onUIImageSubViewWithView:subview];[subview addSubview:ig];
}//view 需要生成的图片
- (UIImage *)onUIImageSubViewWithView:(UIView *)view
{//view容器UIView *subview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(view.frame), CGRectGetWidth(view.frame) * 5.5 /4)];subview.backgroundColor = [UIColor greenColor];[view addSubview:subview];//主图UIImageView *mainimgv = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(subview.frame), CGRectGetWidth(subview.frame))];mainimgv.backgroundColor = [UIColor purpleColor];[subview addSubview:mainimgv];mainimgv.image = [UIImage imageNamed:@"1.png"];//小图标UIImageView *xiaoimgv = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(view.frame) / 20, CGRectGetWidth(view.frame) / 20)];xiaoimgv.backgroundColor = [UIColor purpleColor];[subview addSubview:xiaoimgv];[xiaoimgv mas_makeConstraints:^(MASConstraintMaker *make) {make.top.equalTo(mainimgv.mas_bottom).mas_offset(10);make.left.equalTo(subview).mas_offset(10);make.size.mas_offset(CGSizeMake(CGRectGetWidth(view.frame) / 20, CGRectGetWidth(view.frame) / 20));}];//简介UILabel *nametxt = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];nametxt.text = @"      阿斯顿发大发大发是的发送到发送到发送到附近阿萨德放假啊收到了飞机阿斯顿发卡就是大幅拉升的减肥啦圣诞节费拉达斯放假啊了";nametxt.numberOfLines = 3;[subview addSubview:nametxt];[nametxt mas_makeConstraints:^(MASConstraintMaker *make) {make.top.equalTo(mainimgv.mas_bottom).mas_offset(10);make.left.equalTo(subview).mas_offset(10);make.width.mas_offset(CGRectGetWidth(mainimgv.frame) / 2);}];//小itemviewUIView *xiaosubview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 60, 20)];xiaosubview.layer.masksToBounds = YES;[subview addSubview:xiaosubview];xiaosubview.layer.borderColor = [UIColor redColor].CGColor;xiaosubview.layer.borderWidth = 0.5;[xiaosubview mas_makeConstraints:^(MASConstraintMaker *make) {make.top.equalTo(nametxt.mas_bottom).mas_offset(10);make.left.equalTo(subview).mas_offset(10);make.size.mas_offset(CGSizeMake(60, 20));}];xiaosubview.layer.cornerRadius = CGRectGetHeight(xiaosubview.frame) / 10;//xiao uilatxtUILabel *xiaouilatxt = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];xiaouilatxt.backgroundColor = [UIColor redColor];xiaouilatxt.textColor = [UIColor whiteColor];xiaouilatxt.font = [UIFont systemFontOfSize:11];[xiaosubview addSubview:xiaouilatxt];xiaouilatxt.text = @"券";xiaouilatxt.textAlignment = NSTextAlignmentCenter;[xiaouilatxt mas_makeConstraints:^(MASConstraintMaker *make) {make.top.equalTo(xiaosubview).mas_offset(0);make.left.equalTo(xiaosubview).mas_offset(0);make.bottom.equalTo(xiaosubview).mas_offset(0);make.width.mas_offset(CGRectGetWidth(xiaosubview.frame) / 3);}];//xiao 优惠券UILabel *xiaoquantxt = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];xiaoquantxt.text = @"¥50";xiaoquantxt.font = [UIFont systemFontOfSize:11];xiaoquantxt.textColor = [UIColor redColor];[xiaosubview addSubview:xiaoquantxt];xiaoquantxt.textAlignment = NSTextAlignmentCenter;[xiaoquantxt mas_makeConstraints:^(MASConstraintMaker *make) {make.top.equalTo(xiaosubview).mas_offset(0);make.left.equalTo(xiaouilatxt.mas_right).mas_offset(0);make.bottom.equalTo(xiaosubview).mas_offset(0);make.width.mas_offset(CGRectGetWidth(xiaosubview.frame) * 2 / 3);}];//优惠价UILabel *pricetxt = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];pricetxt.text = @"¥50.0";pricetxt.font = [UIFont systemFontOfSize:15];pricetxt.textColor = [UIColor redColor];[subview addSubview:pricetxt];[pricetxt mas_makeConstraints:^(MASConstraintMaker *make) {make.top.equalTo(xiaosubview.mas_bottom).mas_offset(10);make.left.equalTo(subview).mas_offset(10);make.bottom.equalTo(subview).mas_offset(-10);}];//原价UILabel *oldpricetxt = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];oldpricetxt.text = @"¥150.0";oldpricetxt.font = [UIFont systemFontOfSize:13];oldpricetxt.textColor = [UIColor grayColor];[subview addSubview:oldpricetxt];[oldpricetxt mas_makeConstraints:^(MASConstraintMaker *make) {make.top.equalTo(xiaosubview.mas_bottom).mas_offset(12);make.left.equalTo(pricetxt.mas_right).mas_offset(5);make.bottom.equalTo(subview).mas_offset(-10);}];//链接二维码CGFloat qrH = CGRectGetHeight(subview.frame) - CGRectGetHeight(mainimgv.frame) - 10 * 2;UIImageView *qrimgv = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];qrimgv.backgroundColor = [UIColor yellowColor];[subview addSubview:qrimgv];[qrimgv mas_makeConstraints:^(MASConstraintMaker *make) {make.top.equalTo(mainimgv.mas_bottom).mas_offset(10);make.right.equalTo(subview).mas_offset(-10);make.size.mas_offset(CGSizeMake(qrH, qrH));}];//生成图片return [self makeImageWithView:subview withSize:CGSizeMake(subview.frame.size.width, subview.frame.size.height)];
}//这个方法生成的图片不太清晰  不过把这个方法修改一下  就可以了
#pragma mark 生成image
- (UIImage *)makeImageWithView:(UIView *)view withSize:(CGSize)size
{// 下面方法,第一个参数表示区域大小。第二个参数表示是否是非透明的。如果需要显示半透明效果,需要传NO,否则传YES。第三个参数就是屏幕密度了,关键就是第三个参数 [UIScreen mainScreen].scale。UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);[view.layer renderInContext:UIGraphicsGetCurrentContext()];UIImage *image = UIGraphicsGetImageFromCurrentImageContext();UIGraphicsEndImageContext();return image;}
@end

转载于:https://www.cnblogs.com/shenlaiyaoshi/p/9006092.html

ios -生成推广海报相关推荐

  1. 手把手教你使用PHP生成推广海报

    在日常的工作中(比如微信小程序),我们经常有这样的需求,就是需要使用程序生成推广海报,然后海报里要包含指定的二维码,这样用户分享出去别人扫码之后就可以确定用户推荐关系. 单独生成海报背景或者单独生成二 ...

  2. PHP实现生成推广海报

    经常有这样的需求,就是需要在生成推广海报,包含指定的二维码,分享出去别人扫码之后就可以确定用户推荐关系. 仔细分析一下,推广海报必要的要素就是海报背景图和二维码,这两者都容易生成,但要两者结合到一起组 ...

  3. PHP实现生成推广海报的方法详解

    本文实例讲述了PHP实现生成推广海报的方法.分享给大家供大家参考,具体如下: 经常有这样的需求,就是需要在生成推广海报,包含指定的二维码,分享出去别人扫码之后就可以确定用户推荐关系. 仔细分析一下,推 ...

  4. 使用 iview 实现PC端生成推广海报与二维码并下载的功能,基于iview Modal 对话框 与 Carousel 走马灯组件实现

    使用 iview 实现PC端生成推广海报与二维码并下载的功能,基于iview Modal 对话框 与 Carousel 走马灯组件实现 前言:最近在对公司网页进行改版的时候遇到一个问题,需要在PC端实 ...

  5. 小程序离屏canvas(createOffscreenCanvas)生成推广海报

    小程序离屏canvas(createOffscreenCanvas)生成推广海报 离屏canvas调用wx.canvasToTempFilePath报错Failed to execute 'drawI ...

  6. 原生PHP上传图片并且裁剪图片生成推广海报

    <?phpini_set('memory_limit', '-1'); /***生成宣传海报* @param array 参数,包括图片和文字* @param string $filename ...

  7. Java 动态生成推广海报,带用户头像、昵称、二维码

    继续上一篇文章的延续,二维码生成好的,那么就把他画到海报上吧. 样例(图一是效果图,图二是模板). 工程代码                 那么这里涉及到的知识如下. 绘制单文字 绘制换行文字 绘制 ...

  8. php生成推广二维码海报、合成图片demo

    php生成推广二维码海报.合成图片 1.海报背景图.背景图一般存服务器,程序本地读取: 2.推广二维码.可以是二维码图片链接,也可以是字符串图像流.如果自己生成二维码,详见phpqrcode官网,地址 ...

  9. asp生成带参数的二维码并合成推广海报图片,asp合并合成推广海报图片asp代码

    最近做的一个项目中,客户要求用asp生成二维码,然后合并到一张背景图片上,合并生成一张推广海报来,可把我愁坏了,经过一个晚上的努力,成功了,下面把这个:asp生成带参数的二维码并合成推广海报,asp合 ...

最新文章

  1. 如何自学python基础-零基础如何学习python
  2. jQuery源码解析之position()
  3. (转) Spring读书笔记-----Spring的Bean之配置依赖
  4. linux 导出io,Linux基础知识之IO重定向
  5. binlog数据库不写入binlog_mysql数据库备份及其恢复
  6. 使用Spring Boot CLI的Spring Boot Initilizr
  7. 组件、组件化 与 模块化
  8. 流水作业c语言代码,C语言流水灯
  9. Java毕设项目——网上宠物店管理系统(java+SSM+Maven+Mysql+Jsp)
  10. 什么高大填空四个字动人_什么发亮填空四字词语
  11. 研究生毕业论文如何选题
  12. AI视频生成工具 抖音短视频剪辑软件
  13. Linux设备驱动——第三章字符驱动
  14. C#读取Word文件的方法
  15. 【数字图像处理】Python使用PIL库压缩图片大小——按比例压缩
  16. 百度CEO李彦宏:电子商务平台将在年前发布
  17. linux安装socket.io,Socket.IO
  18. Linux vim编辑文件查找指定的字符串
  19. 实施国家大数据战略 加快建设数据强国
  20. 为什么说DOM操作是昂贵的

热门文章

  1. 重磅!2022年全球汽车零部件供应商百强发布
  2. 【电机原理与拖动基础】Unit 1 直流电机(你还不知道电机是怎么一回事吗?那就快来看一看吧!)
  3. win10软件拒绝访问删不掉_win10结束进程时拒绝访问的处理办法
  4. 双11电商技术:不再谷满谷,坑满坑,看苏宁库存架构转变
  5. 15 年没写代码,濒临被裁,50 岁开发者如何绝地求生?
  6. CSDN日报20170410 ——《未经检视的人生不值得活》
  7. 编程范式(斯坦福大学)学习笔记《四》
  8. 首个Laravel工作流引擎发布 V1.0正式版
  9. hadoop distcp 参数调优_linux性能调优总结 - 星火撩原
  10. UNETR 论文精解