IOS set font to fade color

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.