博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UILabel混合显示动画效果
阅读量:6877 次
发布时间:2019-06-26

本文共 2959 字,大约阅读时间需要 9 分钟。

UILabel混合显示动画效果

 

效果

 

源码

////  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

细节

转载地址:http://tfwbl.baihongyu.com/

你可能感兴趣的文章
JQuery文本框水印插件的简单实现
查看>>
手动fsck修复
查看>>
VBA在Excel中的应用(三)
查看>>
在 Ubuntu 16.04 上安装 LEMP 环境
查看>>
SQL Server profile使用技巧
查看>>
协议中UART的两种模式 【转】
查看>>
SharePoint 2013 Farm 安装指南——Least Privilege
查看>>
C# 温故知新 基础篇(1) C#概述
查看>>
jQuery结合lhgdialog弹出窗口,关闭时出现没有权限错误
查看>>
EXTJS学习系列提高篇:第二十八篇(转载)作者殷良胜,ext2.2打造Ext.form.ComboBox系列--分页显示...
查看>>
如何完成.Net下XML文档的读写操作
查看>>
QTP的那些事--对已经存在Excel文件修改后保存时,会弹出一个询问对话框
查看>>
UVA 11174 Stand in a Line 树dp+算
查看>>
C语言中函数strcpy ,strncpy ,strlcpy的用法【转】
查看>>
mysql join 的同时可以筛选数据
查看>>
Code First开发系列之管理并发和事务
查看>>
Spark SQL概念学习系列之为什么使用 Spark SQL?(二)
查看>>
VirtualBox-Linux系统安装增强功能
查看>>
ssh/ssh2登录
查看>>
mongodb对数组元素及内嵌文档进行增删改查操作(转)
查看>>