View that produces a gradient
Effect
Source
Https://github.com/YouXianMing/GradientColorView
////GradientColorView.h//Gradientcolorview////Created by youxianming on 15/12/15.//copyright©2015 year youxianming. All rights reserved.//#import<UIKit/UIKit.h>@interfaceGradientcolorview: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 has 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 year youxianming. All rights reserved.//#import "GradientColorView.h"@interfaceGradientcolorview () @property (nonatomic, strong) Cagradientlayer*Gradientlayer;@end@implementationGradientcolorview+(Class) layerclass {return[Cagradientlayerclass];}-(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= @[(__bridgeID) [Uicolor Redcolor]. Cgcolor, (__bridgeID) [Uicolor Greencolor]. Cgcolor, (__bridgeID) [Uicolor Bluecolor]. Cgcolor]; } returnSelf ;}- (void) becomeeffective {self.gradientLayer.startPoint=Self.startpoint; Self.gradientLayer.endPoint=Self.endpoint; Self.gradientLayer.colors=self.colors; Self.gradientLayer.locations=self.locations;}@end
Details
View that produces a gradient