前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >CALayer系列、CGContextRef、UIBezierPath、文本属性Attributes

CALayer系列、CGContextRef、UIBezierPath、文本属性Attributes

作者头像
且行且珍惜_iOS
发布2018-05-22 17:07:26
1K0
发布2018-05-22 17:07:26
举报

先上效果图:

CALayer系列.gif

CGContextRef、UIBezierPath、文本属性Attributes.gif

一、CAEmitterLayer 粒子属性

代码语言:javascript
复制
//设置发射器
   CAEmitterLayer *  _snowEmitter=[[CAEmitterLayer alloc]init];
    //发射器在xy平面的中心位置
    _snowEmitter.emitterPosition=CGPointMake(self.view.frame.size.width/2,self.view.frame.size.height/2);
    //发射器的尺寸大小
    _snowEmitter.emitterSize=CGSizeMake(20, 20);
    //发射器的渲染模式
    /*
     kCAEmitterLayerUnordered //这种模式下,粒子是无序出现的,多个发射源将混合
     kCAEmitterLayerOldestFirst //这种模式下,声明久的粒子会被渲染在最上层
     kCAEmitterLayerOldestLast //这种模式下,年轻的粒子会被渲染在最上层
     kCAEmitterLayerBackToFront //这种模式下,粒子的渲染按照Z轴的前后顺序进行
     kCAEmitterLayerAdditive //这种模式会进行粒子混合
     */
    _snowEmitter.renderMode = kCAEmitterLayerBackToFront;
    
    /*emitterShape
     kCAEmitterLayerPoint //点的形状,粒子从一个点发出
     kCAEmitterLayerLine  //线的形状,粒子从一条线发出
     kCAEmitterLayerRectangle //矩形形状,粒子从一个矩形中发出
     kCAEmitterLayerCuboid //立方体形状,会影响Z平面的效果
     kCAEmitterLayerCircle //圆形,粒子会在圆形范围发射
     kCAEmitterLayerSphere //球型
     */
    _snowEmitter.emitterShape = kCAEmitterLayerPoint;
    _snowEmitter.preservesDepth = YES;
    
    /*发射器的发射模式
     kCAEmitterLayerPoints //从发射器中发出
     kCAEmitterLayerOutline //从发射器边缘发出
     kCAEmitterLayerSurface //从发射器表面发出
     kCAEmitterLayerVolume //从发射器中点发出
     */
    _snowEmitter.emitterMode = kCAEmitterLayerVolume;
    
    /*下面是_snowEmitter的一些属性
     _snowEmitter.birthRate //粒子的创建速率,默认为1/s
     lifetime 粒子的存活时间。默认为1S
     emitterZPosition 发射器在Z平面的位置
     emitterDepth  发射器的深度,在某些发射模式下会产生立体效果
     emitterShape  发射器的形状
     emitterMode  发射器的发射模式
     preservesDepth 是否开启三维空间效果
     velocity 粒子的运动速度
     scale 粒子的缩放大小
     spin 粒子的旋转位置
     seed 初始化随机的粒子种子
     */
    
    
    //发射单元
    //火焰
    CAEmitterCell * snow = [CAEmitterCell emitterCell];
    //粒子的创建速率
    snow.birthRate = 22;
    //粒子的生存时间
    snow.lifetime = 2.0;
    //粒子的生存时间容差
    snow.lifetimeRange = 1.5;
    //粒子的颜色
    snow.color = [[UIColor whiteColor]CGColor];
    //渲染粒子,可以设置为一个CGImage的对象
    snow.contents = (id)[[UIImage imageNamed:@"snow.png"]CGImage];
    //设置发射单元的名称
    snow.name = @"snow";
    //粒子的速度
    snow.velocity=160;
    //粒子速度的容差
    snow.velocityRange=80;
    //粒子在xy平面的发射角度
    snow.emissionLongitude= M_PI/2;
    //粒子发射角度的容差
    snow.emissionRange=M_PI/2;
    //缩放速度
    snow.scaleSpeed=0.3;
    //旋转度
    snow.spin=0.2;
    
    /*下面是snow的一些属性
     
     xAcceleration/yAcceleration/zAcceleration; x,y,z三个方向的加速度
     contentsRect 渲染的范围
     
     @property float redRange;
     @property float greenRange;
     @property float blueRange;
     @property float alphaRange;
     粒子在rgb三个色相上的容差和透明度的容差
     
     @property float redSpeed;
     @property float greenSpeed;
     @property float blueSpeed;
     @property float alphaSpeed;
     粒子在RGB三个色相上的变化速度和透明度的变化速度
     
     */
    //粒子单元数组
    _snowEmitter.emitterCells = [NSArray arrayWithObjects:snow,nil];
    [self.view.layer addSublayer:_snowEmitter];

二、CAGradientLayer是用于色彩梯度展示的layer图层

代码语言:javascript
复制
 /*CAGradientLayer的一些属性
     //颜色数组,设置我们需要过的的颜色,必须是CGColor对象
    @property(nullable, copy) NSArray *colors;
   
     //颜色开始进行过渡的位置
     这个数组中的元素是NSNumber类型,单调递增的,并且在0——1之间
     例如,如果我们设置两个颜色进行过渡,这个数组中写入0.5,则第一个颜色会在达到layer一半的时候开始向第二个颜色过渡
    @property(nullable, copy) NSArray<NSNumber *> *locations;
   
     //下面两个参数用于设置渲染颜色的起点和终点 取值范围均为0——1
     默认起点为(0.5 ,0) 终点为(0.5 ,1),颜色的过渡范围就是沿y轴从上向下
    @property CGPoint startPoint;
    @property CGPoint endPoint;
   
     //渲染风格 iOS中只支持一种默认的kCAGradientLayerAxial,我们无需手动设置
    @property(copy) NSString *type;
    */

三、富文本Attributes属性

代码语言:javascript
复制
 /*
     
     NSKernAttributeName(文字间距) : @8
     NSFontAttributeName(字体设置)
     NSForegroundColorAttributeName(字体颜色)
     NSParagraphStyleAttributeName(段落样式)
     NSBackgroundColorAttributeName(背景颜色)
     NSStrokeColorAttributeName(字体边框颜色)和NSStrokeWidthAttributeName(字体边框的宽度),字体边框的宽度是按照和字体的大小进行比例设置的.这两个属性设置完成之后会出现两种效果,如果NSStrokeWidthAttributeName为负数,那么字体为描边,如果NSStrokeWidthAttributeName为正整数,字体的效果就成了空心字.值得注意的是,这两个属性必须要配合着使用,只设置一方面是不能实现效果的。
     NSStrikethroughStyleAttributeName(删除线):@(NSUnderlineStyleSingle)
     NSUnderlineStyleAttributeName(下划线) :@(NSUnderlineStyleSingle)
     NSUnderlineColorAttributeName  设置下划线颜色
     NSVerticalGlyphFormAttributeName(文字排版方向) :@0 ;0表示横排 ,1代表竖排  (没看到效果)
     NSObliquenessAttributeName(文字倾斜) : @5;
     NSExpansionAttributeName(文字扁平化) :@1;
     NSShadowAttributeName(文字阴影) :shadow
     NSShadowAttributeName对应的是NSShadow对象,单一使用不会有任何效果,需要配合着NSVerticalGlyphFormAttributeName(文字排版方向)、NSObliquenessAttributeName(文字倾斜)、NSExpansionAttributeName(文字扁平化)配合使用
     NSWritingDirectionAttributeName(设置文字书写方向):@(NSWritingDirectionRightToLeft) (没看到效果)
     NSLinkAttributeName  设置链接属性,点击后调用浏览器打开指定URL地址
     NSAttachmentAttributeName          设置文本附件,取值为NSTextAttachment对象,常用于文字图片混排

     */

还有CAReplicatorLayer、CAShapeLayer、CATextLayer、CGContextRef、UIBezierPath 用法就不在这里说了,详情可以去Demo中查看或者去参考http://www.jianshu.com/p/3f191880a567http://www.jianshu.com/p/6c9aa9c5dd68

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016.10.18 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档