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 ...
随机推荐
- POJ 3020 Antenna Placement 最大匹配
Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6445 Accepted: 3182 ...
- 虚拟机设置NAT上网
需要开启虚拟机网络相关服务, 安装虚拟网卡VMware虚拟机下实现NAT方式上网1. 把你的虚拟网卡VMnet8设置为自动获得IP.自动获得DNS服务器,启用.2. 把你虚拟机中操作系统的“本地连接” ...
- Solr的精确匹配搜索
情景: 利用Solr做一批词的逆文档频率.Solr中存储的每条数据为一篇文章,此时需要查出某词在多少篇文章中出现过,然后用公式:某词逆文档频率 = 总文章数 / (出现过某词的文章数+1) 来计算. ...
- SpringBoot修改默认端口号
SpringBoot修改默认端口号 server.port=8088 学习了:https://blog.csdn.net/zknxx/article/details/53433592 java -ja ...
- Linux——.bash_profile和.bashrc的区别(如何设置生效)
/etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行.并从/etc/profile.d目录的配置文件中搜集shell的设置./etc/bashrc:为每一个运 ...
- 图解avaScript中this指向(超透彻)
一个图讲清楚JavaScript中this指向: 说明: (1)严格模式下,禁止this关键字指向全局对象会报错. (2)闭包中的this对象具有全局性,因此通常指向window. (3)优先级:n ...
- hadoop native本地库问题总结
近期,打算hbase建表用snappy压缩时,碰到一些hadoop本地库的问题. 事实上这些问题是一直存在的,仅仅是不影响正常使用,就没有引起重视. 这次希望彻底解决下面问题: 问题一:运行start ...
- Jersey 1.18 API文档
Jersey 1.18 API文档 我自己制作了Jersey 1.18 API CHM文档, 下载地址见: http://download.csdn.net/detail/chszs/7334869 ...
- 删除LINUX更新后多余的内核
删除LINUX更新后多余的内核 本人使用的时fredoa 21 之前为了搞网卡驱动不知不觉升级了几次系统,每次启动后都有好几个内核让我选,真的非常头疼阿,尤其像博主这样的有点强迫的人,看着就心烦,所以 ...
- 10、驱动中的阻塞与非阻塞IO
阻塞,就是在获取资源的时候,不能获取到,那么就会将当前的进程挂起(睡眠,也就是将当前进程从调度器拿走了,不会调度当前进程),直到满足条件为止再进行操作.相反,非阻塞,就是即使不能获取到资源,非 ...
