UILabel混合显示动画效果

UILabel混合显示动画效果

 

效果

 

源码

https://github.com/YouXianMing/Animations

//
//  MixedColorProgressViewController.m
//  Animations
//
//  Created by YouXianMing on 16/1/5.
//  Copyright  2016年 YouXianMing. All rights reserved.
//

#import "MixedColorProgressViewController.h"
#import "UIView+SetRect.h"
#import "GCD.h"

@interface MixedColorProgressViewController ()

@property (nonatomic, strong)  UIView   *upView;
@property (nonatomic, strong)  UILabel  *upLabel;
@property (nonatomic, strong)  UIView   *downView;
@property (nonatomic, strong)  UILabel  *downLabel;

@property (nonatomic, strong)  GCDTimer *timer;

@end

@implementation MixedColorProgressViewController

- (void)setup {

    [super setup];

    /*
     给upView的frame值做动画才是label能够混色显示的核心

     upView(红色背景)   ===>  upLabel(白色底字)
     |                       |
     |                       |
     |                       |
     |                       |
     downView(白色背景) ===> downLabel(红色底字)

     */

    // 上面一层
    {
        // 红色背景
        _upView                     = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 220, 17)];
        _upView.center              = self.view.center;
        _upView.layer.cornerRadius  = 2.f;
        _upView.backgroundColor     = [UIColor redColor];
        _upView.layer.masksToBounds = YES; // 核心(不让subview显示超出范围)
        [self.view addSubview:_upView];

        // 白色底字
        _upLabel                    = [[UILabel alloc] initWithFrame:_upView.bounds];
        _upLabel.font               = [UIFont fontWithName:@"HelveticaNeue-Thin" size:13];
        _upLabel.text               = @"YouXianMing - iOS Programmer";
        _upLabel.textColor          = [UIColor whiteColor];
        _upLabel.textAlignment      = NSTextAlignmentCenter;
        [_upView addSubview:_upLabel];
    }

    // 下面一层
    {
        // 白色背景
        _downView                     = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 220, 17)];
        _downView.center              = self.view.center;
        _downView.layer.cornerRadius  = 2.f;
        _downView.backgroundColor     = [UIColor whiteColor];
        [self.view addSubview:_downView];

        // 红色底字
        _downLabel                    = [[UILabel alloc] initWithFrame:_downView.bounds];
        _downLabel.textColor          = [UIColor redColor];
        _downLabel.font               = [UIFont fontWithName:@"HelveticaNeue-Thin" size:13];
        _downLabel.text               = @"YouXianMing - iOS Programmer";
        _downLabel.textAlignment = NSTextAlignmentCenter;
        [_downView addSubview:_downLabel];
    }

    // 显示上面一层
    [self.view bringSubviewToFront:_upView];

    // 给上面一层的frame值做动画
    _timer = [[GCDTimer alloc] initInQueue:[GCDQueue mainQueue]];
    [_timer event:^{

        [UIView animateWithDuration:0.5f delay:0.f usingSpringWithDamping:3.f initialSpringVelocity:0 options:0 animations:^{

            _upView.width = arc4random() % 220;

        } completion:nil];

    } timeInterval:NSEC_PER_SEC];
    [_timer start];
}

@end

细节

时间: 2024-08-03 00:08:27

UILabel混合显示动画效果的相关文章

高逼格UILabel的闪烁动画效果

高逼格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, stro

UILabel的缩放动画效果

UILabel的缩放动画效果   效果图   源码 https://github.com/YouXianMing/Animations // // ScaleLabel.h // Animations // // Created by YouXianMing on 15/12/17. // Copyright 2015年 YouXianMing. All rights reserved. // #import <UIKit/UIKit.h> @interface ScaleLabel : UI

jquery实现隐藏与显示动画效果/输入框字符动态递减/导航按钮切换

jquery实现隐藏显示层动画效果.仿新浪字符动态输入.tab效果等等,以下为所有代码,感兴趣的朋友可以练练手哈,希望对大家学习有所帮助   已经有两年多没登陆csdn账号了,中间做了些旁的事,可是现在却还是回归程序,但改做前端了,虽然很多东西都已忘得差不多了,但还是应该摆正心态,慢慢来,在前端漫游,做一只快乐双鱼. 路是一步一步走出来的,知识是一点一滴积累的,记录是笔财富,来吧,一起学着总结做笔记. 这几天在写后台文章的一些页面,为了能得到更好的交互性,需要做一些效果,js无疑使不二之选,但由

Android开发之SurfaceView显示动画效果

一.基础知识: SurfaceView继承自View,View负责在主线程中更新动画,而SurfaceView是在一个新线程中更新动画. SurfaceView类的主要方法: // 在SurfaceView创建时调用 pubilic abstract void surfaceCreated(SurfaceHolder holder) // 在SurfaceView改变时调用 pubilic abstract void surfaceChanged(SurfaceHolder holder, in

Android Animation动画实战(一): 从布局动画引入ListView滑动时,每一Item项的显示动画

前言:   之前,我已经写了两篇博文,给大家介绍了Android的基础动画是如何实现的,如果还不清楚的,可以点击查看:Android Animation动画详解(一): 补间动画 及 Android Animation动画详解(二): 组合动画特效 . 已经熟悉了基础动画的实现后,便可以试着去实现常见APP中出现过的那些精美的动画.今天我主要给大家引入一个APP的ListView的动画效果: 当展示ListView时,Listview的每一个列表项都按照规定的动画显示出来.   说起来比较抽象,

Android Animation实战之一个APP的ListView的动画效果_Android

熟悉了基础动画的实现后,便可以试着去实现常见APP中出现过的那些精美的动画.今天我主要给大家引入一个APP的ListView的动画效果: 当展示ListView时,Listview的每一个列表项都按照规定的动画显示出来. 说起来比较抽象,先给大家看一个动画效果,这是APP窝牛装修的ListView显示动画:     有木有觉得很酷炫?有木有啊!? 一.Layout Animation     所谓的布局动画,其实就是为ViewGroup添加显示动画效果,主要用过LayoutAnimationCo

Android Animation实战之一个APP的ListView的动画效果

熟悉了基础动画的实现后,便可以试着去实现常见APP中出现过的那些精美的动画.今天我主要给大家引入一个APP的ListView的动画效果: 当展示ListView时,Listview的每一个列表项都按照规定的动画显示出来. 说起来比较抽象,先给大家看一个动画效果,这是APP窝牛装修的ListView显示动画: 有木有觉得很酷炫?有木有啊!? 一.Layout Animation     所谓的布局动画,其实就是为ViewGroup添加显示动画效果,主要用过LayoutAnimationContro

AngularJS中实现显示或隐藏动画效果的方式总结_AngularJS

AngularJS 是一组用于创建单页Web应用的丰富框架,给构建丰富交互地应用带来了所有需要的功能.其中一项主要的特性就是Angular带来了对动画的支持. 本篇体验在AngularJS中实现在"显示/隐藏"这2种状态切换间添加动画效果. 通过CSS方式实现显示/隐藏动画效果 思路: →npm install angular-animage →依赖:var app = angular.module("app",["ngAnimate"]); →

浏览器-缓存到本地的网页文件canvas的动画效果无法显示是为什么?

问题描述 缓存到本地的网页文件canvas的动画效果无法显示是为什么? 学习h5效果的时候,通过浏览器的页面功能保存了含有通过canvas实现动画效果的网页,用域名访问时很正常,但从本地打开html文件时就是与之前打开的完全不同的页面,js和css文件没有缺失,请问这是什么原因?有没有办法通过打开本地的文件来查看效果 解决方案 http://jingyan.baidu.com/article/ab0b563093c6b6c15afa7db8.html?st=2&os=0&bd_page_t