Quartz2D使用(信纸条纹)
Quartz2D使用(信纸条纹)
一、前导程序
新建一个项目,在主控制器文件中实现以下几行代码,就能轻松的完成图片在视图中的平铺。
1 #import "YYViewController.h"2 3 @interface YYViewController ()4 5 @end6 7 @implementation YYViewController8 9 - (void)viewDidLoad 10 { 11 [super viewDidLoad]; 12 13 UIImage *image=[UIImage imageNamed:@"me"]; 14 UIColor *color=[UIColor colorWithPatternImage:image]; 15 self.view.backgroundColor=color; 16 } 17 18 @end
效果:
二、实现信纸条纹的效果
1 //8 9 #import "YYViewController.h" 10 11 @interface YYViewController () 12 13 @end 14 15 @implementation YYViewController 16 17 - (void)viewDidLoad 18 { 19 [super viewDidLoad]; 20 21 22 // 1.生成一张以后用于平铺的小图片 23 CGSize size = CGSizeMake(self.view.frame.size.width, 35); 24 UIGraphicsBeginImageContextWithOptions(size , NO, 0); 25 26 // 2.画矩形 27 CGContextRef ctx = UIGraphicsGetCurrentContext(); 28 CGFloat height = 35; 29 CGContextAddRect(ctx, CGRectMake(0, 0, self.view.frame.size.width, height)); 30 [[UIColor whiteColor] set]; 31 CGContextFillPath(ctx); 32 33 // 3.画线条 34 35 CGFloat lineWidth = 2; 36 CGFloat lineY = height - lineWidth; 37 CGFloat lineX = 0; 38 CGContextMoveToPoint(ctx, lineX, lineY); 39 CGContextAddLineToPoint(ctx, 320, lineY); 40 [[UIColor blackColor] set]; 41 CGContextStrokePath(ctx); 42 43 44 UIImage *image=UIGraphicsGetImageFromCurrentImageContext(); 45 UIColor *color=[UIColor colorWithPatternImage:image]; 46 self.view.backgroundColor=color; 47 } 48 49 @end
效果:
三、应用场景
完成一个简陋的电子书阅读器
代码:
8 9 #import "YYViewController.h" 10 11 @interface YYViewController () 12 13 @property (weak, nonatomic) IBOutlet UITextView *textview; 14 - (IBAction)perBtnClick:(UIButton *)sender; 15 - (IBAction)nextBtnClick:(UIButton *)sender; 16 @property(nonatomic,assign)int index; 17 @end 18 19 @implementation YYViewController 20 21 - (void)viewDidLoad 22 { 23 [super viewDidLoad]; 24 25 26 // 1.生成一张以后用于平铺的小图片 27 CGSize size = CGSizeMake(self.view.frame.size.width, 26); 28 UIGraphicsBeginImageContextWithOptions(size , NO, 0); 29 30 // 2.画矩形 31 CGContextRef ctx = UIGraphicsGetCurrentContext(); 32 CGFloat height = 26; 33 CGContextAddRect(ctx, CGRectMake(0, 0, self.view.frame.size.width, height)); 34 [[UIColor brownColor] set]; 35 CGContextFillPath(ctx); 36 37 // 3.画线条 38 39 CGFloat lineWidth = 2; 40 CGFloat lineY = height - lineWidth; 41 CGFloat lineX = 0; 42 CGContextMoveToPoint(ctx, lineX, lineY); 43 CGContextAddLineToPoint(ctx, 320, lineY); 44 [[UIColor blackColor] set]; 45 CGContextStrokePath(ctx); 46 47 48 UIImage *image=UIGraphicsGetImageFromCurrentImageContext(); 49 UIColor *color=[UIColor colorWithPatternImage:image]; 50 //self.view.backgroundColor=color; 51 self.textview.backgroundColor=color; 52 } 53 54 - (IBAction)perBtnClick:(UIButton *)sender { 55 self.index--; 56 self.textview.text=[NSString stringWithFormat:@"第%d页",self.index]; 57 CATransition *ca = [[CATransition alloc] init]; 58 ca.type = @"pageCurl"; 59 60 [self.textview.layer addAnimation:ca forKey:nil]; 61 62 } 63 64 - (IBAction)nextBtnClick:(UIButton *)sender { 65 self.index++; 66 self.textview.text=[NSString stringWithFormat:@"第%d页",self.index]; 67 CATransition *ca = [[CATransition alloc] init]; 68 ca.type = @"pageCurl"; 69 70 [self.textview.layer addAnimation:ca forKey:nil]; 71 } 72 @end
storyboard中的界面布局
实现的简单效果:
转载于:https://www.cnblogs.com/crash-wu/p/4797285.html
Quartz2D使用(信纸条纹)相关推荐
- iOS开发UI篇—Quartz2D使用(信纸条纹)
iOS开发UI篇-Quartz2D使用(信纸条纹) 一.前导程序 新建一个项目,在主控制器文件中实现以下几行代码,就能轻松的完成图片在视图中的平铺. 1 #import "YYViewCon ...
- iOS开发UI高级—26Quartz2D使用(信纸条纹)
iOS开发UI篇-Quartz2D使用(信纸条纹) 一.前导程序 新建一个项目,在主控制器文件中实现以下几行代码,就能轻松的完成图片在视图中的平铺. 1 #import "YYViewCon ...
- 利用Quartz2D设置自定义条纹背景
1.设置平铺背景 self.view.backgroundColor = [UIColor colorWithPatternImage:newImage]; 2.设置拉伸背景 UIImage *old ...
- iOS--开发从入门到精通
前言: 从事iOS开发已有几个年头,平时对于iOS开发的知识积累都比较碎片化,为了更好的掌握开发技能, 索性整理iOS开发的知识体系,以便于后面进阶成iOS高级开发工程师. 一.iOS开发基础 开发设 ...
- 文顶顶iOS开发博客链接整理及部分项目源代码下载
网上的iOS开发的教程很多,但是像cnblogs博主文顶顶的博客这样内容图文并茂,代码齐全,示例经典,原理也有阐述,覆盖面宽广,自成系统的系列教程却很难找.如果你是初学者,在学习了斯坦福iOS7公开课 ...
- Quartz2D绘图
2019独角兽企业重金招聘Python工程师标准>>> 绘图路径 A.简单说明 在画线的时候,方法的内部默认创建一个path.它把路径都放到了path里面去. 1.创建路径 cgm ...
- (四十七)Quartz2D引擎初步
Quartz2D是跨平台的,同时支持iOS与Mac. 支持圆型裁剪,可以实现圆形头像等功能,也支持手势解锁.折线图等的制作. 对于复杂的UI界面,还可以通过Quartz2D将控件内部的结构画出来,可用 ...
- Quartz2D在项目中的实际使用
还记得大学刚学iOS那会,从学校图书馆借了本iOS开发的书,有一章节介绍了Quartz2D,当时看得一头雾水,感觉这画画线,画画圆有什么用呢
- 聊聊三维重建-条纹法之相位法(一)
点击上方"3D视觉工坊",选择"星标" 干货第一时间送达 本文由知乎作者Tengfei Jiang授权转载,不得擅自二次转载. 原文链接: https://zh ...
最新文章
- python基础语法第10关作业-【python基础语法】第8天作业练习题
- 大数据技术 学习之旅_如何开始您的数据科学之旅?
- 【今日CS 视觉论文速览】Fri, 21 Dec 2018
- Ubuntu 安装 python-opencv
- Python imageio方法示例
- WPF UI 框架 收集
- DIY专门制作PCB的雕刻机--所需软件
- 数据标注工具YEDDA
- day32,尚硅谷视频学习中
- 千图成像!祝可爱的小伙伴们圣诞快乐
- 刷脸信息采集坚持用户授权最小够用的原则
- 基于Android的医院预下单叫号排队系统
- 2011年美国大学招生广告
- 【ARCore 入门开发课程系列】ARCore 打造沉浸式体验全过程
- 求两个单链表的差集和并集
- 这个企业邮箱登陆入口更快捷
- 不只是同构应用(isomorphic 工程化你所忽略的细节)
- 自己动手实现俄罗斯方块
- 虚拟机安装教程win10_虚拟机安装实战教程
- 彻底解决 webpack 打包文件体积过大
热门文章
- 《微图4.0》升级更新
- Latex 表格整体居中
- NLog整合Exceptionless
- Tomcat+nginx项目在浏览器报安全隐患以及图片加载失败原因
- 如何利用sql查找表中的重复数据?
- 谷歌浏览器chrome,元素elements页面鼠标右键不起作用不想赢
- c语言勾股定理程序流程图,方法总结1.表达算法的方法有自然语言.流程图和基本算法语句三种.先有自然语言.再画流程图.最后才能写出基本算法语句.即程序,——青夏教育精英家教网——...
- Pycharm 提示Untrusted Server‘s certificate 证书不可用( Server‘s certificate is not trusted )
- cas5.3.9自定义手机短信验证码登录
- Vue中,methods中调用filters里的过滤器