UILabel混合显示动画效果
动画 显示 效果 混合 UILabel
2023-09-14 08:57:30 时间
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; @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
细节
UISlider滑动条的高度系统默认给我们设定了,没有办法进行改变。可是,我们的设计又是需要改变这个高度的,怎么办呢?这个时候,我们可以写一个UISlider的子类,重写四个方法就能实现了。
相关文章
- GPT-3组合DALL·E,60秒内搞定游戏设定和原型动画!网友看后:这游戏想玩
- 【愚公系列】2022年09月 微信小程序-WebGL动画的使用
- android缩放动画中心缩放_安卓动画缩放调到多少比较好
- Tab Bar动画效果
- 就用它了!炫酷的粒子动画特效轻松搞定
- iOS呼吸动画
- 【Flutter】Animation 动画 ( Flutter 动画的核心类 | Animation | CurvedAnimation | AnimationController | Tween )
- 【Flutter】Animation 动画 ( Flutter 动画基本流程 | 创建动画控制器 | 创建动画 | 设置值监听器 | 设置状态监听器 | 布局中使用动画值 | 动画运行 )
- KeyShot Pro for mac(3D渲染和动画制作软件)
- iOS 动画退出应用代码详解手机开发
- android动画之interpolator和typeEvaluator用法详解手机开发
- 大疆不仅为工程师办比赛,还为他们量身制作了一部动画
- JS仿Flash动画放大/缩小容器
- jQuery动画效果-fadeInfadeOut淡入浅出示例代码
- VC++实现输出GIF到窗体并显示GIF动画的方法
- Android实现Flip翻转动画效果