Objective-C - How to make a gradient text UILabel

tag: Objective-C    date: 2018-10-12

create a gradient background image you want with photoshop

Here is the gradient image:

create a gradient uiview

UIView *gradientView = [[UIView alloc] initWithFrame:(CGRect){10,30,300,100}];
gradientView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"gradient-bg.png"]];
[self.view addSubview:gradientView];

create an uilabel for test

UILabel *label = [[UILabel alloc] initWithFrame:(CGRect){10,30,300,100}];
label.text = @"Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.";
label.numberOfLines = 0;
label.font = [UIFont boldSystemFontOfSize:20];
[self.view addSubview:label];

set the uiview's mask

gradientView.maskView = label;

Here is the result:

Download The Project

more articles
Copyright © 2018
This Site is Licensed under a Creative Commons License. Powerd by Java