zoukankan      html  css  js  c++  java
  • 产生渐变色的view

    产生渐变色的view

    效果

    源码

    https://github.com/YouXianMing/UI-Component-Collection

    //
    //  GradientColorView.h
    //  GradientColorView
    //
    //  Created by YouXianMing on 15/12/15.
    //  Copyright © 2015年 YouXianMing. All rights reserved.
    //
    
    #import <UIKit/UIKit.h>
    
    @interface GradientColorView : UIView
    
    /**
     *  CGColor's array.
     */
    @property (nonatomic, strong) NSArray   *colors;
    
    /**
     *  CGColor's location.
     */
    @property (nonatomic, strong) NSArray   *locations;
    
    /**
     *  Start point.
     */
    @property (nonatomic) CGPoint startPoint;
    
    /**
     *  End point.
     */
    @property (nonatomic) CGPoint endPoint;
    
    /**
     *  After you have set all the properties, you should run this method to make effective.
     */
    - (void)becomeEffective;
    
    @end
    //
    //  GradientColorView.m
    //  GradientColorView
    //
    //  Created by YouXianMing on 15/12/15.
    //  Copyright © 2015年 YouXianMing. All rights reserved.
    //
    
    #import "GradientColorView.h"
    
    @interface GradientColorView ()
    
    @property (nonatomic, strong) CAGradientLayer  *gradientLayer;
    
    @end
    
    @implementation GradientColorView
    
    + (Class)layerClass {
        
        return [CAGradientLayer class];
    }
    
    - (instancetype)initWithFrame:(CGRect)frame {
        
        if (self = [super initWithFrame:frame]) {
            
            _gradientLayer  = (CAGradientLayer *)self.layer;
            self.startPoint = CGPointMake(0, 0);
            self.endPoint   = CGPointMake(1, 0);
            self.locations  = @[@(0.25), @(0.5), @(0.75)];
            self.colors     = @[(__bridge id)[UIColor redColor].CGColor,
                                (__bridge id)[UIColor greenColor].CGColor,
                                (__bridge id)[UIColor blueColor].CGColor];
        }
        
        return self;
    }
    
    - (void)becomeEffective {
        
        self.gradientLayer.startPoint = self.startPoint;
        self.gradientLayer.endPoint   = self.endPoint;
        self.gradientLayer.colors     = self.colors;
        self.gradientLayer.locations  = self.locations;
    }
    
    @end

    细节

  • 相关阅读:
    Oracle性能调整ASH,AWR,ADDM
    子网掩码、子网划分详解
    10046事件sql_trace跟踪
    find详解
    date详解
    touch详解
    [转]lsof详解
    iftop、ifstat详解
    iotop详解
    关于Unity的入门游戏飞机大战的开发(上)
  • 原文地址:https://www.cnblogs.com/YouXianMing/p/5049702.html
Copyright © 2011-2022 走看看