IOS 绘制条纹背景
@interface NJViewController ()
@property (weak, nonatomic) IBOutlet UITextView *contentView;
- (IBAction)preBtnClick:(id)sender;
- (IBAction)nextBtnClick:(id)sender; @property (nonatomic, assign) int index; @end @implementation NJViewController - (void)viewDidLoad
{
[super viewDidLoad]; // // 1.生成一张以后用于平铺的小图片
CGSize size = CGSizeMake(self.view.frame.size.width, );
UIGraphicsBeginImageContextWithOptions(size , NO, ); // 2.画矩形
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGFloat height = ;
CGContextAddRect(ctx, CGRectMake(, , self.view.frame.size.width, height));
[[UIColor redColor] set];
CGContextFillPath(ctx); // 3.画线条 CGFloat lineWidth = ;
CGFloat lineY = height - lineWidth;
CGFloat lineX = ;
CGContextMoveToPoint(ctx, lineX, lineY);
CGContextAddLineToPoint(ctx, , lineY);
[[UIColor blackColor] set];
CGContextStrokePath(ctx); UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIColor *myColor = [UIColor colorWithPatternImage:image];
self.contentView.backgroundColor = myColor; } - (void)test
{
// 1.生成一张以后用于平铺的小图片
CGSize size = CGSizeMake(self.view.frame.size.width, );
UIGraphicsBeginImageContextWithOptions(size , NO, ); // 2.画矩形
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGFloat height = ;
CGContextAddRect(ctx, CGRectMake(, , self.view.frame.size.width, height));
[[UIColor redColor] set];
CGContextFillPath(ctx); // 3.画线条 CGFloat lineWidth = ;
CGFloat lineY = height - lineWidth;
CGFloat lineX = ;
CGContextMoveToPoint(ctx, lineX, lineY);
CGContextAddLineToPoint(ctx, , lineY);
[[UIColor blackColor] set];
CGContextStrokePath(ctx); UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); /*
// 2.将图片写到文件中
NSString *path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"aaa.png"];
NSLog(@"%@", path); NSData *data = UIImagePNGRepresentation(image);
[data writeToFile:path atomically:YES];
*/ // UIImage *image = [UIImage imageNamed:@"me"];
// UIColor *myColor = [UIColor colorWithPatternImage:image];
// self.view.backgroundColor = myColor;
} // 今天不要求掌握以下内容
- (IBAction)preBtnClick:(id)sender
{
self.index--; self.contentView.text = [NSString stringWithFormat:@"第%d页", self.index]; CATransition *ca = [[CATransition alloc] init];
ca.type = @"pageCurl"; [self.contentView.layer addAnimation:ca forKey:nil];
} - (IBAction)nextBtnClick:(id)sender
{
self.index++; self.contentView.text = [NSString stringWithFormat:@"第%d页", self.index];
}
IOS 绘制条纹背景的更多相关文章
- 用css实现条纹背景
我先额外的说一下怎么用CSS绘制三角形: 绘制三角形是把边框加粗,将元素的宽高都设为0,让其余的边框颜色透明,下面我们来看实现的代码: 先把边框的颜色设置成不同颜色: #div{ border-col ...
- css条纹背景样式、及方格斜纹背景的实现
一.横向条纹如下代码: background: linear-gradient(#fb3 %, #58a %) 上面代码表示整个图片的上部分20%和下部分20%是对应的纯色,只有中间的部分是渐变色.如 ...
- iOS中点击背景收键盘
这一次给大家带来的是ios中点击背景如何收键盘(感觉不错给个赞
- CSS揭秘 技巧(五):条纹背景
条纹背景 https://github.com/FannieGirl/ifannie/问题:条纹背景 在设觉设计中无处不在,我们真的可以用css 创建图案吗? 这一章相对还是比较复杂的哦!一起get. ...
- css条纹背景
一. 水平条纹 1. 两种颜色: html <div class="stripe"></div> css .stripe{ width: 250px; he ...
- 利用CCS3渐变实现条纹背景
本文摘自<CSS揭秘>中国工信出版集团 难题: 不论是在网页设计中,还是在其他传统媒介中(比如杂志和墙纸等),各种尺寸.颜色.角度的条纹图案在视觉设计中无处不在.要想在网页中实现条纹图案, ...
- [css 揭秘] :CSS揭秘 技巧(五):条纹背景
条纹背景 https://github.com/FannieGirl/ifannie/问题:条纹背景 在设觉设计中无处不在,我们真的可以用css 创建图案吗? 这一章相对还是比较复杂的哦!一起get. ...
- 使用android.graphics.Path类自绘制PopupWindow背景
PopupWindow简单介绍 PopupWindow是悬浮在当前activity上的一个容器,用它能够展示随意的内容. PopupWindow跟位置有关的API有以下几个: showAsDropDo ...
- C#绘制渐变背景
//绘制渐变色背景 Graphics g = e.Graphics; LinearGradientBrush linearGradientBrush = new LinearGradientBrush ...
随机推荐
- 死磕 java同步系列之开篇
简介 同步系列,这是彤哥想了好久的名字,本来是准备写锁相关的内容,但是java中的CountDownLatch.Semaphore.CyclicBarrier这些类又不属于锁,它们和锁又有很多共同点, ...
- 置换群(本蒟蒻瞎BB的)(未完)
置换群(本蒟蒻瞎BB的)(未完) 群的定义 给定一个集合\(G=\{a, b, c...\}\)和集合\(G\)上的二元运算*,并满足: 封闭性:\(\forall a, b \in G, \exis ...
- scapy框架
性能相关 在编写爬虫时,性能的消耗主要在IO请求中,当单进程单线程模式下请求URL时必然会引起等待,从而使得请求整体变慢. import requests def fetch_async(url): ...
- Objective-C对象的申请空间与初始化
对象分配空间与初始化 对象分配空间与初始化 使用Objective-C语言创建一个对象有两个步骤,你必须: 为新对象动态分配内存空间 初始化新分配的内存,并赋初值 不经过如上两步,一个对象就没有完全功 ...
- Effective Java第一节
第1条:考虑用静态工厂方法代替构造器 首先清楚什么是静态工厂方法? 静态工厂方法说白了就是在创建对象的时候,不是自己使用new关键字创建的,而是使用静态方法来对外提供自身的实例的方法. 比如: Fra ...
- POJ1045 Bode Plot
题目来源:http://poj.org/problem?id=1045 题目大意: 如图所示的交流电路,假设电路处于稳定状态,Vs为电源电压,w是频率,单位为弧度每秒,t表示时间. 则:V1 = Vs ...
- [Leetcode]011. Container With Most Water
public class Solution { public int maxArea(int[] height) { int left = 0, right = height.length - 1; ...
- P2375 [NOI2014]动物园 KMP
好,暴力能拿$50pts\space qwq$ 暴力的思路就是一直跳$nxt[j]$,直到它的长度小于串的一半,然后开始计数,当然要接着跳$nxt[j]$ 正解:考虑没有长度要求的(不要求不重合)公共 ...
- Batch the files in the directory
#!/bin/bash #sourceFolder = /home/bigdatagfts/pl62716/refdata #targetFolder = /home/bigdatagfts/pl62 ...
- js——swiper.js
一款用于PC端和移动端的滑动效果插件. 中文网站:http://www.swiper.com.cn/# 点击中文教程.使用方法 1. initialSlide:初始索引值,从0开始 2.pagin ...