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 ...
随机推荐
- ubuntu_software_install
1.atom PPA安装 命令行上依次输入即可完成安装: sudo add-apt-repository ppa:webupd8team/atom sudo apt-get update sudo a ...
- fedora25安装和docker-ce_清华源
docker-ce_清华源 https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/fedora/ fedora25 docker-ce版本: htt ...
- 安装dubbo-admin报错 URIType BeanCreationException
安装dubbo-admin报错 URIType BeanCreationException 学习了:https://blog.csdn.net/lsm135/article/details/52725 ...
- MyISAM的key_buffer_size和InnoDB的innodb_buffer_pool_size
一.MyISAM的key_buffer_size MyISAM的索引方式是非聚集索引,主索引和其他索引没有本质区别,在data域都是存储了具体记录行的地址.key_buffer_size规定了系统将多 ...
- Unity Shader 效果学习
Unity上对于图像的处理,假设单纯使用代码.那么非常遗憾,程序基本会跑死,毕竟是直接对像素的操作,读取写入都是比較耗费CPU和内存的. 所以.这次由于项目须要想实现类似哈哈镜的效果.想来想去,还是认 ...
- zh-cn en-uk表示语言(文化)代码与国家地区对照表
af 公用荷兰语 af-ZA 公用荷兰语 - 南非 sq 阿尔巴尼亚 sq-AL 阿尔巴尼亚 -阿尔巴尼亚 ar 阿拉伯语 ar-DZ 阿拉伯语 -阿尔及利亚 ar-BH 阿拉伯语 -巴林 ar-EG ...
- margin: 0px auto; center 行类 块级
<html> <head> <title> biaoti </title> </head> <body style="bor ...
- Cocos2D-X2.2.3学习笔记10(几何图形)
我们这节来学习几何图形,即怎样使用Cocos2d-x绘制各种图形.已经贝塞尔曲线 我们查看CCNode中有个draw函数,我们须要将绘制的代码所有写在这个函数里面.写在init函数里是画不出线来的, ...
- QT学习二:工具栏
QT 的工具栏提供 Dock 功能.文字/图标显示排列的功能. void MainWindow::createToolBar(void) { QToolBar *toolBar = new QToo ...
- C++语言基础(3)-类和对象
类是创建对象的模板,一个类可以创建多个对象,每个对象都是类类型的一个变量:创建对象的过程也叫类的实例化.每个对象都是类的一个具体实例(Instance),拥有类的成员变量和成员函数. 一.类的定义 一 ...
