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 ...
随机推荐
- linux中查找文件属于那个软件包的方法
一.linux中查找文件属于那个软件包的方法 [root@salt prod]# whereis htpasswdhtpasswd: /usr/bin/htpasswd /usr/share/man/ ...
- Yii添加验证码
添加带验证码的登陆: 1.先在模型modules下的LoginForm.php定义一个存储验证码的变量:public $verfyCode: 2.然后在rules()方法里定义:array('veri ...
- 简单工厂模式 SimpleFactory
简单工厂模式 SimpleFactory 1.1什么是简单工厂设计模式 简单工厂模式是属于创建型模式,又叫做静态工厂方法(Static Factory Method)模式,但不属于23种GOF设计模 ...
- Java 多线程之 synchronized 和 volatile 的比較
概述 在做多线程并发处理时,常常须要对资源进行可见性訪问和相互排斥同步操作.有时候,我们可能从前辈那里得知我们须要对资源进行 volatile 或是 synchronized 关键字修饰处理.但是,我 ...
- IT痴汉的工作现状21-Android开发前景论
饭间闲谈 齐天.周权和我是饭搭子.总是边吃边聊一些与技术.汽车和女人相关的话题. "前阵子Nokia裁员之事不知道完没完?这艾洛普挺能作啊."我吃着香喷喷的过桥米线说." ...
- 微信团队原创分享:iOS版微信的内存监控系统技术实践
本文来自微信开发团队yangyang的技术分享. 一.前言 FOOM(Foreground Out Of Memory),是指App在前台因消耗内存过多引起系统强杀.对用户而言,表现跟crash一样. ...
- 初识FASTBuild 一个大幅提升C/C++项目编译速度的分布式编译工具
FASTBuild 是一款高性能.开源的构建系统,支持高度可扩展的编译,缓存和网络分发. 以上是FASTBuild官网对其产品的一句话介绍. FASTBuild 的开源地址:https://githu ...
- Tony zhao:到底怎么样才叫看书?
http://blog.jobbole.com/25842/ 目录: 一.引入 二.经历了就能理解 三.读书要分级 四.只读经典 五.别吝惜你动笔的那点时间 一.引入 看到这个题目的时候你可能会感到有 ...
- mongoDB GUI客户端工具大全
网易blog - MongoDB GUI客户端工具大全 oschina - MonjaDB 1.0.2 发布,MongoDB 的 GUI 客户端 oschina创建人红薯对MonjaDB官方文 ...
- ScrollView嵌套ListView冲突问题的最优解决方式
项目做多了之后.会发现事实上ScrollView嵌套ListVew或者GridView等非经常常使用,可是你也会发现各种奇怪问题产生.依据个人经验如今列出常见问题以及代码最少最简单的解决方法. 问题一 ...
