zoukankan      html  css  js  c++  java
  • UIBezierPath,CAShaperLayer,

    a、利用UIBezierPath在DrawRect:中绘制一个给定颜色的三角位图,代码如下:

    - (void)drawRect:(CGRect)rect

    { // Drawing code

        UIBezierPath *path = [UIBezierPath bezierPath];

        [path moveToPoint:CGPointMake(rect.size.width/2, 0)];

        [path addLineToPoint:CGPointMake(rect.size.width, rect.size.height)];

        [path addCurveToPoint:CGPointMake(0, rect.size.height) controlPoint1:CGPointMake(rect.size.width/2, rect.size.height) controlPoint2:CGPointMake(rect.size.width/2, rect.size.height)];

        [path closePath];

        [[UIColor colorWithRed:25.0/255 green:141.0/225 blue:200.0/255 alpha:1] setStroke];

        [[UIColor colorWithRed:25.0/255 green:141.0/225 blue:200.0/255 alpha:1] setFill];

        [path stroke];

        [path fill];

        self.layer.shadowColor = [UIColor blackColor].CGColor;

        self.layer.shadowRadius = 3;

        self.layer.shadowOpacity = 0.4;

    //    self.layer.shadowPath = [];

    }

    b、UIBezierPath和CAShapelayer的组合使用,其实是CAShaperLayer可以拥有一个自己的贝塞尔路径,绘制一左右两半颜色不同的图层视图,代码如下:

    #import "BezierView.h"

    @interface BezierView()

    {

        CAShapeLayer *_leftLayer;

        UIBezierPath *_leftPath;

        CAShapeLayer *_rightLayer;

        UIBezierPath *_rightPath;

    }

    @end

    @implementation BezierView

    - (id)initWithFrame:(CGRect)frame

    {

        self = [super initWithFrame:frame];

        if (self) {

            // Initialization code

            _leftSpan = self.frame.size.width/4;

            _leftLayer = [[CAShapeLayer alloc] init];

            [self.layer addSublayer:_leftLayer];//将图层添加添加上去。

            _leftLayer.fillColor = nil;

            _leftLayer.frame = self.bounds;

            _rightLayer = [[CAShapeLayer alloc] init];

            [self.layer addSublayer:_rightLayer];//图层的添加

            _rightLayer.fillColor = nil;

            _rightLayer.frame = self.bounds;

            self.backgroundColor = [UIColor blueColor];        

        }

        return self;

    }

    -(void)setLeftOne

    {

        _leftPath = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, _leftSpan, self.frame.size.height)];

        _leftLayer.path = _leftPath.CGPath;

    }

    -(void)setRightOne

    {

        _rightPath = [UIBezierPath bezierPathWithRect:CGRectMake(_leftSpan, 0, self.frame.size.width-_leftSpan, self.frame.size.height)];

        _rightLayer.path = _rightPath.CGPath;

    }

    -(void)setRightColor:(UIColor *)rightColor

    {

        _rightLayer.fillColor = rightColor.CGColor;

        [self setRightOne];

    }

    -(void)setLeftColor:(UIColor *)leftColor

    {

        _leftLayer.fillColor = leftColor.CGColor;

        [self setLeftOne];

    }

    -(void)setLeftSpan:(CGFloat)leftSpan

    {

        _leftSpan = leftSpan;

        [self setLeftOne];

        [self setRightOne];

    }

    /*

    // Only override drawRect: if you perform custom drawing.

    // An empty implementation adversely affects performance during animation.

    - (void)drawRect:(CGRect)rect

    {

        // Drawing code

    }

    */

    @end

  • 相关阅读:
    很实用的html meta标签实现页面跳转
    oracle 实例名和服务名以及数据库名区别
    Oracle 创建 DBLink 的方法
    Java (六):java中Math常用方法
    Java (四):String,StringBuilder,StringBuffer三者的区别
    ROS Learning-001 安装 ROS indigo
    Windows cmd 将命令(/指令)写到一个文件里,直接运行这个文件。提高工作效率
    Blender 基础 骨架-02 骨架的各种呈现方式
    Blender 基础 骨架 01
    Python 解决 :NameError: name 'reload' is not defined 问题
  • 原文地址:https://www.cnblogs.com/longtaozi/p/3835324.html
Copyright © 2011-2022 走看看