高逼格UILabel的闪烁动画效果

最终效果图如下:

源码:

YXLabel.h 与  YXLabel.m

//
// YXLabel.h
//
// Created by YouXianMing on 14-8-23.
// Copyright (c) 2014年 YouXianMing. All rights reserved.
// #import <UIKit/UIKit.h> @interface YXLabel : UIView @property (nonatomic, strong) NSString *text; // 文本的文字
@property (nonatomic, strong) UIFont *font; // 文本的字体 @property (nonatomic, assign) CGFloat startScale; // 最初处于alpha = 0状态时的scale值
@property (nonatomic, assign) CGFloat endScale; // 最后处于alpha = 0状态时的scale值 @property (nonatomic, strong) UIColor *backedLabelColor; // 不会消失的那个label的颜色
@property (nonatomic, strong) UIColor *colorLabelColor; // 最终会消失的那个label的颜色 - (void)startAnimation; @end
//
// YXLabel.m
//
// Created by YouXianMing on 14-8-23.
// Copyright (c) 2014年 YouXianMing. All rights reserved.
// #import "YXLabel.h" @interface YXLabel () @property (nonatomic, strong) UILabel *backedLabel;
@property (nonatomic, strong) UILabel *colorLabel; @end @implementation YXLabel - (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
_backedLabel = [[UILabel alloc] initWithFrame:self.bounds];
_colorLabel = [[UILabel alloc] initWithFrame:self.bounds]; // 初始时的alpha值为0
_backedLabel.alpha = ;
_colorLabel.alpha = ; // 文本居中
_backedLabel.textAlignment = NSTextAlignmentCenter;
_colorLabel.textAlignment = NSTextAlignmentCenter; [self addSubview:_backedLabel];
[self addSubview:_colorLabel];
}
return self;
} - (void)startAnimation
{
// 判断endScale的值
if (_endScale == ) {
_endScale = .f;
} // 开始第一次动画
[UIView animateWithDuration:
delay:
usingSpringWithDamping:
initialSpringVelocity:
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
// 恢复正常尺寸
_backedLabel.alpha = .f;
_backedLabel.transform = CGAffineTransformMake(, , , , , ); _colorLabel.alpha = .f;
_colorLabel.transform = CGAffineTransformMake(, , , , , );;
}
completion:^(BOOL finished) { // 开始第二次动画
[UIView animateWithDuration:
delay:0.5
usingSpringWithDamping:
initialSpringVelocity:
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
_colorLabel.alpha = .f;
_colorLabel.transform = CGAffineTransformMake(_endScale, , , _endScale, , );
}
completion:^(BOOL finished) { }];
}];
} #pragma mark - 重写setter方法
@synthesize text = _text;
- (void)setText:(NSString *)text
{
_text = text;
_backedLabel.text = text;
_colorLabel.text = text;
}
- (NSString *)text
{
return _text;
} @synthesize startScale = _startScale;
- (void)setStartScale:(CGFloat)startScale
{
_startScale = startScale;
_backedLabel.transform = CGAffineTransformMake(startScale, , , startScale, , );
_colorLabel.transform = CGAffineTransformMake(startScale, , , startScale, , );
}
- (CGFloat)startScale
{
return _startScale;
} @synthesize font = _font;
- (void)setFont:(UIFont *)font
{
_font = font;
_backedLabel.font = font;
_colorLabel.font = font;
}
- (UIFont *)font
{
return _font;
} @synthesize backedLabelColor = _backedLabelColor;
- (void)setBackedLabelColor:(UIColor *)backedLabelColor
{
_backedLabelColor = backedLabelColor;
_backedLabel.textColor = backedLabelColor;
} @synthesize colorLabelColor = _colorLabelColor;
- (void)setColorLabelColor:(UIColor *)colorLabelColor
{
_colorLabelColor = colorLabelColor;
_colorLabel.textColor = colorLabelColor;
} @end

使用的源码:

//
// RootViewController.m
// Demo
//
// Created by YouXianMing on 14-8-22.
// Copyright (c) 2014年 YouXianMing. All rights reserved.
// #import "RootViewController.h"
#import "YXLabel.h"
#import "FontPool.h" @interface RootViewController () @end @implementation RootViewController - (void)viewDidLoad
{
[super viewDidLoad]; self.view.backgroundColor = [UIColor blackColor]; // 注册字体
REGISTER_FONT(bundleFont(@"新蒂小丸子小学版.ttf"), @"新蒂小丸子小学版"); YXLabel *label = [[YXLabel alloc] initWithFrame:CGRectMake(, , , )];
label.text = @"高逼格";
label.startScale = 0.3f;
label.endScale = .f;
label.backedLabelColor = [UIColor whiteColor];
label.colorLabelColor = [UIColor cyanColor];
label.font = [UIFont fontWithName:CUSTOM_FONT(@"新蒂小丸子小学版", )
size:.f];
label.center = self.view.center;
[self.view addSubview:label]; [[GCDQueue mainQueue] execute:^{
[label startAnimation];
} afterDelay:NSEC_PER_SEC * ]; } @end

其实,笔者并没有把所有的接口都写好,一大早6点钟起床写代码.......,剩下的就交给你了:)

最新文章

  1. dede 优化打开速度
  2. 编写一个Java应用程序,该应用程序包括2个类:Print类和主类E。Print 类里有一个方法output()功能是输出100 ~ 999之间的所有水仙花数(各位数字的 立方和等于这个三位数本身,如: 371 = 33 + 73 + 13。)在主类E的main方法中来 测试类Print
  3. 定一个小目标:明年1024能成功转行web前端,光荣地成为一个程序员!
  4. How far away[HDU2586]
  5. RabbitMQ学习总结 第五篇:路由Routing
  6. 笔记本_hp
  7. Itext导出PDF,word,图片案例
  8. 关于ButterKnife 8.1.0使用遇到的问题
  9. String详解说明
  10. Linux内核头文件与内核与库的关系
  11. 七字真言解读TCP三次握手
  12. 最详细的浏览器css hack
  13. Apache配置虚拟主机后,不能访问localhost
  14. java中的final和volatile详解
  15. LCS问题(最长公共子序列)-动态规划实现
  16. 解决配置Windows Update失败问题
  17. Django学习手册 - ORM 多对多表
  18. 实现Python与STM32通信
  19. Android 聊天功能
  20. echarts.js多图表数据展示使用小结

热门文章

  1. Git版本回退和撤销修改
  2. Git修改文件
  3. Ubuntu 16.04 compare 软件安装
  4. css3中比较少用到的属性记录
  5. Java入门系列-12-成员方法
  6. android studio应用修改到android源码中作为内置应用
  7. 了解下C#异常时的输出
  8. 互联网轻量级框架SSM-查缺补漏第三天
  9. JavaScript之如何对客户端进行检测
  10. maven配置环境