ios -生成推广海报
#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 -生成推广海报的更多相关文章
- C# 实现生成带二维码的专属微信公众号推广海报
原文:C# 实现生成带二维码的专属微信公众号推广海报 很多微信公众号中需要生成推广海报的功能,粉丝获得专属海报后可以分享到朋友圈或发给朋友,为公众号代言邀请好友即可获取奖励的.海报自带渠道二维码,粉丝 ...
- 重学 Java 设计模式:实战模版模式「模拟爬虫各类电商商品,生成营销推广海报场景」
作者:小傅哥 博客:https://bugstack.cn - 原创系列专题文章 沉淀.分享.成长,让自己和他人都能有所收获! 一.前言 黎明前的坚守,的住吗? 有人举过这样一个例子,先给你张北大的录 ...
- Vue生成分享海报(含二维码)
本文已同步到专业技术网站 www.sufaith.com, 该网站专注于前后端开发技术与经验分享, 包含Web开发.Nodejs.Python.Linux.IT资讯等板块. 功能需求: 海报有1张背景 ...
- ios 生成问题
上午的时候遇到ios打包的时候出现问题,生成没有问题,但是安装到手机的时候出现问题,错误如下 The certificate used to sign "AppName" has ...
- iOS生成静态库方法
在iOS的开发过程中,我们常常用到第三方的库.比如支付.地图.广告等. 那么,如何制作自己的库文件呢? 如何将自己写的功能类编译成库文件,分发给其他人来使用呢并做成通用库里? iOS开发一年多来没有制 ...
- 手把手教iOS生成.a包及常见的问题
我的例子是打包MJRefresh 环境OS10.11.4, XCode Version 7.3.1 (7D1014) 生成.a如下: 创建新工程: 把下载的 MJRefresh-master加到你的 ...
- IOS 生成设备唯一标识
前言 iOS设备5.0以上放弃使用[[UIDevice currentDevice] uniqueIdentifier]来获得设备唯一ID iOS设备私有方法禁止用户获取和使用IMEI 需求 需要一个 ...
- iOS生成Bundle包及使用
什么是Bundle文件? 简单理解,就是资源文件包.我们将许多图片.XIB.文本文件组织在一起,打包成一个Bundle文件.方便在其他项目中引用包内的资源. Bundle文件的特点? Bundle是静 ...
- ios生成自签名证书,实现web下载安装app
抄自http://beyondvincent.com/blog/2014/03/17/five-tips-for-using-self-signed-ssl-certificates-with-ios ...
随机推荐
- CreatarGlobe实现多机立体显示方案(初稿)
CreatarGlobe实现多机立体显示方案(初稿) 关键字 : 集群渲染 立体显示 大屏幕 边缘融合 多机同步 多机同步显示 关键字: 大屏幕投影融合系统解决方案 集群渲染 多机3D同步显示又称“集 ...
- Java笔记6:多态
一.多态的分类对象的多态性:动物 x = new 猫();函数的多态性:函数重载.重写 二.多态的体现父类的引用指向了自己的子类对象父类的引用也可以接收自己的对象 三.多态的前提必须是类与类之间只有关 ...
- <LeetCode OJ> 101. Symmetric Tree
101. Symmetric Tree My Submissions Question Total Accepted: 90196 Total Submissions: 273390 Difficul ...
- Elasticsearch 理解
概述 Elasticsearch (ES)是一个基于 Lucene 的开源搜索引擎,它不但稳定.可靠.快速,而且也具有良好的水平扩展能力,是专门为分布式环境设计的. 特性 安装方便:没有其他依赖,下载 ...
- Mybatis学习记录(一)---- 简单的CRUD
1 mybatis是什么? mybatis是一个持久层的框架,是apache下的顶级项目. mybatis托管到googlecode下,再后来托管到github下(https://github.com ...
- 倍福TwinCAT(贝福Beckhoff)常见问题(FAQ)-TwinCAT自带的找原点功能块MC_Home怎么用
对于相对编码器类型轴(包括虚拟轴),可以使用贝福提供的找原点功能块MC_Home. HomingMode是指机器在往前跑的时候(30单位/s的默认速度),当碰到阻挡,则会有一个布尔值从FALSE改 ...
- Android自己定义(三)实现圆盘的百分比设置
近期一直在学习自己定义控件,昨天看到群里有人问怎样怎样实现圆盘样式的显示,学有所用,于是乎就有了这篇博客 先上图,一目了然 这里的显示颜色以及颜色块的大小你都能够自己设置 这里设置了三种颜色,相应三种 ...
- libevent2源码分析之一:前言
event的本质 libevent2中的event的本质是什么?只要是非同步阻塞的运行方式,肯定遵循事件的订阅-发布模型.通过event_new的函数原型可以理解,一个event即代表一次订阅,建立起 ...
- 提高PAAS安全性的一点尝试
云服务已经成为现代人生活的一部分.手机中的照片会自己主动同步到云中:你的邮件内容保存在云中.办公软件执行在云中:你的健康数据会实时上传到云中.你每天的生活轨迹消耗的卡路里也会上传到云中:云服务也会逐渐 ...
- 【Java】Java_05 标识符与字符集
1.标识符 用作给变量.类和方法命名.注意: 表示类名的标识符用大写字母开始.如:Man, GoodMan 表示方法和变量的标识符用小写字母开始,后面的描述性词以大写开始.green(),greenC ...
