This tutorial for the Animating on UILabel that label enabling the blinking the text shading the text then inner shadow on text then gradient fill into the text.

Sample Output

AnimatedLabel

Following code is use for the blinking the text on UILabel.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
- (void)blinkAnimation:(NSString *)animationID finished:(BOOL)finished target:(UIView *)target
{
    NSString *selectedSpeed = [[NSUserDefaults standardUserDefaults] stringForKey:@"EffectSpeed"];
    float speedFloat = (1.00 - [selectedSpeed floatValue]);
    [UIView beginAnimations:animationID context:target];
    [UIView setAnimationDuration:speedFloat];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(blinkAnimation:finished:target:)];
    if([target alpha] == 1.0f)
        [target setAlpha:0.0f];
    else
        [target setAlpha:1.0f];
    [UIView commitAnimations];
}

Following code is use for call the method.

1
[self blinkAnimation:@"blinkAnimation" finished:YES target:labelView];

Now, Going to implement another Animation on the UILable.

Copy Following file into your Project then Implement Following code into you viewcontroller.h file

1
2
3
4
5
6
7
8
9
10
11
#import <UIKit/UIKit.h>
#import "FXLabel.h"
@interface FXLabelExampleViewController : UIViewController
@property (nonatomic, retain) IBOutlet FXLabel *label1;
@property (nonatomic, retain) IBOutlet FXLabel *label2;
@property (nonatomic, retain) IBOutlet FXLabel *label3;
@property (nonatomic, retain) IBOutlet FXLabel *label4;
@end

Following Code is implemented into the viewcontroller.m file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#import "FXLabelExampleViewController.h"
@implementation FXLabelExampleViewController
@synthesize label1;
@synthesize label2;
@synthesize label3;
@synthesize label4;
- (void)viewDidLoad
{
    [super viewDidLoad];
    //demonstrate shadow
    label1.shadowOffset = CGSizeMake(0.0f, 2.0f);
    label1.shadowColor = [UIColor colorWithWhite:0.0f alpha:0.75f];
    label1.shadowBlur = 5.0f;
    //demonstrate inner shadow
    label2.shadowColor = [UIColor colorWithWhite:1.0f alpha:0.8f];
    label2.shadowOffset = CGSizeMake(1.0f, 2.0f);
    label2.shadowBlur = 1.0f;
    label2.innerShadowColor = [UIColor colorWithWhite:0.0f alpha:0.8f];
    label2.innerShadowOffset = CGSizeMake(1.0f, 2.0f);
    //demonstrate gradient fill
    label3.gradientStartColor = [UIColor redColor];
    label3.gradientEndColor = [UIColor blackColor];
    //everything
    label4.shadowColor = [UIColor blackColor];
    label4.shadowOffset = CGSizeZero;
    label4.shadowBlur = 20.0f;
    label4.innerShadowColor = [UIColor yellowColor];
    label4.innerShadowOffset = CGSizeMake(1.0f, 2.0f);
    label4.gradientStartColor = [UIColor redColor];
    label4.gradientEndColor = [UIColor yellowColor];
    label4.gradientStartPoint = CGPointMake(0.0f, 0.5f);
    label4.gradientEndPoint = CGPointMake(1.0f, 0.5f);
}
- (void)viewDidUnload
{
    self.label1 = nil;
    self.label2 = nil;
    self.label3 = nil;
    self.label4 = nil;
    [super viewDidUnload];
}
- (void)dealloc
{
    [label1 release];
    [label2 release];
    [label3 release];
    [label4 release];
    [super dealloc];
}
@end

 

Grab the source code for Animation on UILabel here.

Output

Comming up.

Thanks and Regards,
Nimit Parekh.

Advertisements