Method class
#import "Healp.h"@implementationHealp/*view is the control for which you want to set the gradient font Bgview is the parent view of the view colors is the constituent color of the gradient startpoint is the start point of the gradient endpoint the end point*/+(void) Textgradientview: (UIView *) View Bgview: (UIView *) Bgview gradientcolors: (Nsarray *) Colors Gradientstartpoint: (cgpoint) startPoint endPoint: (cgpoint) endpoint{Cagradientlayer* GradientLayer1 =[Cagradientlayer layer]; Gradientlayer1.frame=View.frame; Gradientlayer1.colors=colors; Gradientlayer1.startpoint=StartPoint; Gradientlayer1.endpoint=EndPoint; [Bgview.layer Addsublayer:gradientlayer1]; Gradientlayer1.mask=View.layer; View.frame=gradientlayer1.bounds;}/*control is the controls to set the gradient font Bgview is the parent view of the control colors is the composition color of the gradient startpoint is the start point of the gradient endpoint the end point*/+(void) Textgradientcontrol: (Uicontrol *) control Bgview: (UIView *) Bgview gradientcolors: (Nsarray *) Colors Gradientstartpoint: (cgpoint) startPoint endPoint: (cgpoint) endpoint{Cagradientlayer* GradientLayer1 =[Cagradientlayer layer]; Gradientlayer1.frame=Control.frame; Gradientlayer1.colors=colors; Gradientlayer1.startpoint=StartPoint; Gradientlayer1.endpoint=EndPoint; [Bgview.layer Addsublayer:gradientlayer1]; Gradientlayer1.mask=Control.layer; Control.frame=gradientlayer1.bounds;}
Reference
/*Method 1*/UILabel* TestLabel = [[UILabel alloc] Initwithframe:cgrectmake ( -, $, -, -)]; Testlabel.text=@"label on gradient Method 1"; Testlabel.font= [Uifont systemfontofsize: -]; [Self.view Addsubview:testlabel]; [Healp Textgradientview:testlabel BgVIew:self.view gradientcolors:@[(ID) [Uicolor Redcolor]. Cgcolor, (ID) [Uicolor Greencolor]. Cgcolor, (ID) [Uicolor Bluecolor]. Cgcolor] Gradientstartpoint:cgpointmake (0,1) Endpoint:cgpointmake (1,1)]; /*Method 2*/_label=[[uilabel Alloc]initwithframe:cgrectmake (Ten, -, self.view.frame.size.width- -, -)]; [Self.view Addsubview:_label]; _label.text=@"label on gradient Method 2"; _label.textalignment=Nstextalignmentcenter; _label.font= [Uifont systemfontofsize: -]; _label.textcolor=[uicolor colorwithpatternimage:[uiimage imagenamed:@"Gradient"]]; _BTN=[[uibutton Alloc]initwithframe:cgrectmake (Ten, -, self.view.frame.size.width- -, -)]; [Self.view ADDSUBVIEW:_BTN]; _btn.titlelabel.font=[uifont systemfontofsize: -]; _btn.titlelabel.numberoflines=0; [_btn settitle:@"font Gradient setting on button"Forstate:uicontrolstatenormal]; [Healp textgradientcontrol:_btn BgVIew:self.view gradientcolors:@[(ID) [Uicolor Redcolor]. Cgcolor, (ID) [Uicolor Greencolor]. Cgcolor, (ID) [Uicolor Bluecolor]. Cgcolor] Gradientstartpoint:cgpointmake (0,1) Endpoint:cgpointmake (1,1)];
IOS set font to fade color