倒計時特效的CountAnimationLabel

來源:互聯網
上載者:User

標籤:style   blog   http   color   io   使用   ar   for   strong   

倒計時特效的CountAnimationLabel

效果:

源碼:

CountAnimationLabel.h 與 CountAnimationLabel.m

////  CountAnimationLabel.h//  YouXianClock////  Created by YouXianMing on 14-10-14.//  Copyright (c) 2014年 YouXianMing. All rights reserved.//#import <UIKit/UIKit.h>@interface CountAnimationLabel : 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, assign) NSTimeInterval  fadeInDuration;   // 預設值為1s@property (nonatomic, assign) NSTimeInterval  fadeOutDuration;  // 預設值為2s@property (nonatomic, assign) NSTimeInterval  showDuration;     // 預設值為0.5s@property (nonatomic, assign) BOOL            removeOnComplete; // 動畫結束後是否被移除掉- (void)startAnimation;@end
////  CountAnimationLabel.m//  YouXianClock////  Created by YouXianMing on 14-10-14.//  Copyright (c) 2014年 YouXianMing. All rights reserved.//#import "CountAnimationLabel.h"@interface CountAnimationLabel ()@property (nonatomic, strong) UILabel  *backedLabel;@end@implementation CountAnimationLabel- (instancetype)initWithFrame:(CGRect)frame{    self = [super initWithFrame:frame];    if (self) {        _backedLabel = [[UILabel alloc] initWithFrame:self.bounds];                // 初始時的alpha值為0        _backedLabel.alpha = 0;                // 文本置中        _backedLabel.textAlignment = NSTextAlignmentCenter;                [self addSubview:_backedLabel];    }    return self;}- (void)startAnimation{    // 判斷endScale的值    if (_endScale == 0) {        _endScale = 2.f;    }        // 開始第一次動畫    [UIView animateWithDuration:(_fadeInDuration > 0 ?_fadeInDuration : 1.f)                          delay:0         usingSpringWithDamping:7          initialSpringVelocity:4                        options:UIViewAnimationOptionCurveEaseInOut                     animations:^{                         // 恢複正常尺寸                         _backedLabel.alpha     = 1.f;                         _backedLabel.transform = CGAffineTransformMake(1, 0, 0, 1, 0, 0);                     }                     completion:^(BOOL finished) {                                                  // 開始第二次動畫                         [UIView animateWithDuration:(_fadeOutDuration > 0 ? _fadeOutDuration : 2.f)                                               delay:(_showDuration > 0 ? _showDuration : 0.5f)                              usingSpringWithDamping:7                               initialSpringVelocity:4                                             options:UIViewAnimationOptionCurveEaseInOut                                          animations:^{                                              _backedLabel.alpha     = 0.f;                                              _backedLabel.transform = CGAffineTransformMake(_endScale, 0, 0, _endScale, 0, 0);                                          }                                          completion:^(BOOL finished) {                                              if (_removeOnComplete == YES) {                                                  [self removeFromSuperview];                                              }                                          }];                     }];}#pragma mark - 重寫setter,getter方法#pragma mark - 重寫setter方法@synthesize text = _text;- (void)setText:(NSString *)text{    _text             = text;    _backedLabel.text = text;}- (NSString *)text{    return _text;}@synthesize startScale = _startScale;- (void)setStartScale:(CGFloat)startScale{    _startScale = startScale;    _backedLabel.transform = CGAffineTransformMake(startScale, 0, 0, startScale, 0, 0);}- (CGFloat)startScale{    return _startScale;}@synthesize font = _font;- (void)setFont:(UIFont *)font{    _font = font;    _backedLabel.font = font;}- (UIFont *)font{    return _font;}@synthesize backedLabelColor = _backedLabelColor;- (void)setBackedLabelColor:(UIColor *)backedLabelColor{    _backedLabelColor = backedLabelColor;    _backedLabel.textColor = backedLabelColor;}@end

以下是使用詳情:

 

倒計時特效的CountAnimationLabel

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.