#import "ViewController.h"
#import "Masonry.h"
@interface ViewController () @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; //一般的view生成图片方法
UIView *subview = [[UIView alloc]initWithFrame:CGRectMake(, , CGRectGetWidth(self.view.frame) - * , CGRectGetHeight(self.view.frame) - * )];
[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(, , 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(, , CGRectGetWidth(view.frame), CGRectGetWidth(view.frame) * 5.5 /)];
subview.backgroundColor = [UIColor greenColor];
[view addSubview:subview]; //主图
UIImageView *mainimgv = [[UIImageView alloc]initWithFrame:CGRectMake(, , 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(, , CGRectGetWidth(view.frame) / , CGRectGetWidth(view.frame) / )];
xiaoimgv.backgroundColor = [UIColor purpleColor];
[subview addSubview:xiaoimgv];
[xiaoimgv mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(mainimgv.mas_bottom).mas_offset();
make.left.equalTo(subview).mas_offset();
make.size.mas_offset(CGSizeMake(CGRectGetWidth(view.frame) / , CGRectGetWidth(view.frame) / )); }]; //简介
UILabel *nametxt = [[UILabel alloc]initWithFrame:CGRectMake(, , , )];
nametxt.text = @" 阿斯顿发大发大发是的发送到发送到发送到附近阿萨德放假啊收到了飞机阿斯顿发卡就是大幅拉升的减肥啦圣诞节费拉达斯放假啊了";
nametxt.numberOfLines = ;
[subview addSubview:nametxt];
[nametxt mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(mainimgv.mas_bottom).mas_offset();
make.left.equalTo(subview).mas_offset();
make.width.mas_offset(CGRectGetWidth(mainimgv.frame) / );
}]; //小itemview
UIView *xiaosubview = [[UIView alloc]initWithFrame:CGRectMake(, , , )];
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();
make.left.equalTo(subview).mas_offset();
make.size.mas_offset(CGSizeMake(, ));
}];
xiaosubview.layer.cornerRadius = CGRectGetHeight(xiaosubview.frame) / ; //xiao uilatxt
UILabel *xiaouilatxt = [[UILabel alloc]initWithFrame:CGRectMake(, , , )];
xiaouilatxt.backgroundColor = [UIColor redColor];
xiaouilatxt.textColor = [UIColor whiteColor];
xiaouilatxt.font = [UIFont systemFontOfSize:];
[xiaosubview addSubview:xiaouilatxt];
xiaouilatxt.text = @"券";
xiaouilatxt.textAlignment = NSTextAlignmentCenter;
[xiaouilatxt mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(xiaosubview).mas_offset();
make.left.equalTo(xiaosubview).mas_offset();
make.bottom.equalTo(xiaosubview).mas_offset();
make.width.mas_offset(CGRectGetWidth(xiaosubview.frame) / );
}]; //xiao 优惠券
UILabel *xiaoquantxt = [[UILabel alloc]initWithFrame:CGRectMake(, , , )];
xiaoquantxt.text = @"¥50";
xiaoquantxt.font = [UIFont systemFontOfSize:];
xiaoquantxt.textColor = [UIColor redColor];
[xiaosubview addSubview:xiaoquantxt];
xiaoquantxt.textAlignment = NSTextAlignmentCenter;
[xiaoquantxt mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(xiaosubview).mas_offset();
make.left.equalTo(xiaouilatxt.mas_right).mas_offset();
make.bottom.equalTo(xiaosubview).mas_offset();
make.width.mas_offset(CGRectGetWidth(xiaosubview.frame) * / );
}]; //优惠价
UILabel *pricetxt = [[UILabel alloc]initWithFrame:CGRectMake(, , , )];
pricetxt.text = @"¥50.0";
pricetxt.font = [UIFont systemFontOfSize:];
pricetxt.textColor = [UIColor redColor];
[subview addSubview:pricetxt];
[pricetxt mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(xiaosubview.mas_bottom).mas_offset();
make.left.equalTo(subview).mas_offset();
make.bottom.equalTo(subview).mas_offset(-);
}]; //原价
UILabel *oldpricetxt = [[UILabel alloc]initWithFrame:CGRectMake(, , , )];
oldpricetxt.text = @"¥150.0";
oldpricetxt.font = [UIFont systemFontOfSize:];
oldpricetxt.textColor = [UIColor grayColor];
[subview addSubview:oldpricetxt];
[oldpricetxt mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(xiaosubview.mas_bottom).mas_offset();
make.left.equalTo(pricetxt.mas_right).mas_offset();
make.bottom.equalTo(subview).mas_offset(-);
}]; //链接二维码
CGFloat qrH = CGRectGetHeight(subview.frame) - CGRectGetHeight(mainimgv.frame) - * ;
UIImageView *qrimgv = [[UIImageView alloc]initWithFrame:CGRectMake(, , , )];
qrimgv.backgroundColor = [UIColor yellowColor];
[subview addSubview:qrimgv];
[qrimgv mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(mainimgv.mas_bottom).mas_offset();
make.right.equalTo(subview).mas_offset(-);
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

ios -生成推广海报的更多相关文章

  1. C# 实现生成带二维码的专属微信公众号推广海报

    原文:C# 实现生成带二维码的专属微信公众号推广海报 很多微信公众号中需要生成推广海报的功能,粉丝获得专属海报后可以分享到朋友圈或发给朋友,为公众号代言邀请好友即可获取奖励的.海报自带渠道二维码,粉丝 ...

  2. 重学 Java 设计模式:实战模版模式「模拟爬虫各类电商商品,生成营销推广海报场景」

    作者:小傅哥 博客:https://bugstack.cn - 原创系列专题文章 沉淀.分享.成长,让自己和他人都能有所收获! 一.前言 黎明前的坚守,的住吗? 有人举过这样一个例子,先给你张北大的录 ...

  3. Vue生成分享海报(含二维码)

    本文已同步到专业技术网站 www.sufaith.com, 该网站专注于前后端开发技术与经验分享, 包含Web开发.Nodejs.Python.Linux.IT资讯等板块. 功能需求: 海报有1张背景 ...

  4. ios 生成问题

    上午的时候遇到ios打包的时候出现问题,生成没有问题,但是安装到手机的时候出现问题,错误如下 The certificate used to sign "AppName" has ...

  5. iOS生成静态库方法

    在iOS的开发过程中,我们常常用到第三方的库.比如支付.地图.广告等. 那么,如何制作自己的库文件呢? 如何将自己写的功能类编译成库文件,分发给其他人来使用呢并做成通用库里? iOS开发一年多来没有制 ...

  6. 手把手教iOS生成.a包及常见的问题

    我的例子是打包MJRefresh 环境OS10.11.4,  XCode Version 7.3.1 (7D1014) 生成.a如下: 创建新工程: 把下载的 MJRefresh-master加到你的 ...

  7. IOS 生成设备唯一标识

    前言 iOS设备5.0以上放弃使用[[UIDevice currentDevice] uniqueIdentifier]来获得设备唯一ID iOS设备私有方法禁止用户获取和使用IMEI 需求 需要一个 ...

  8. iOS生成Bundle包及使用

    什么是Bundle文件? 简单理解,就是资源文件包.我们将许多图片.XIB.文本文件组织在一起,打包成一个Bundle文件.方便在其他项目中引用包内的资源. Bundle文件的特点? Bundle是静 ...

  9. ios生成自签名证书,实现web下载安装app

    抄自http://beyondvincent.com/blog/2014/03/17/five-tips-for-using-self-signed-ssl-certificates-with-ios ...

随机推荐

  1. dx12 memory management

    https://msdn.microsoft.com/en-us/library/windows/desktop/dn508285(v=vs.85).aspx Map with D3D11_MAP_W ...

  2. WIN7怎样把屏幕改为16位色

    1 右击桌面,选择屏幕分辨率   2 选择高级设置   3 点击"监视器"选项卡,把颜色改为16位.   4 屏幕会暂时黑屏一段时间,随后主题将自动切换为基础版(失去Areo效果) ...

  3. lodash 类型判断

    1.isArray _.isArray(value) 检查 value 是否是 Array 类对象. 2.isElement _.isElement(value) 检查 value 是否是可能是 DO ...

  4. <转>巧用notepad++ 批量转换ansi 和 utf8

    原方出处:http://stackoverflow.com/questions/7256049/notepad-converting-ansi-encoded-file-to-utf-8 Here s ...

  5. 【MyBatis学习13】MyBatis中的二级缓存

    1. 二级缓存的原理 前面介绍了,mybatis中的二级缓存是mapper级别的缓存,值得注意的是,不同的mapper都有一个二级缓存,也就是说,不同的mapper之间的二级缓存是互不影响的.为了更加 ...

  6. EF中多表公共字段,以及设置EntityBase使所有实体类继承自定义类

    使用EF框架访问数据库时,如果某些表具有公共字段,例如在审核流程中,对于各类申请单资料的创建人.创建时间.修改人.修改时间,这些可能多表都需要的字段,如果在每个实体中进行赋值操作显然是类似和重复的,下 ...

  7. android-gradle-深入浅出-五:build type

    默认情况下,Android插件自动为项目构建一个debug和一个release版本的应用.这两个版本的不同主要体现在在非开发机上的调试功能以及APK的签名方式.debug版本使用一个用公开的name/ ...

  8. python下载腾讯云慢日志并发送邮件附件

    这里没优化,只是对腾讯云下载慢日志,然后通过邮件发送出去 #!/usr/bin/env python # encoding: utf-8 import json import smtplib impo ...

  9. 【从0開始Tornado建站】0.9版本号python站点代码开源--持续更新中

            从5月份開始[从0開始Tornado建站]这个专栏,開始一点一点把这个分类兴趣站点弄起来,从无到有的过程也是令人兴奋的:-) 国庆的时候等待备案然后上线,如今站点域名为ustchack ...

  10. ISA2006安装和部署基础(虚拟机非域环境)

    0x00. 为了測试基于HTTP隧道的绕过ISA,必须搭建模拟环境,为了不麻烦,我们这里不配合域环境认证.本次实验利用Vmware 10.0搭建好开发环境,实现ISA2006安装和部署,同一时候设定基 ...