实现UILabel渐变色效果
实现UILabel渐变色效果
效果如下图:
源码:
//
// CombinationView.h
// ChangeColorLabel
//
// Created by YouXianMing on 14/11/15.
// Copyright (c) 2014年 YouXianMing. All rights reserved.
// #import <UIKit/UIKit.h> @interface CombinationView : UIView /**
* 上面的view与下面的view
*/
@property (nonatomic, strong) UIView *bottomView;
@property (nonatomic, strong) UIView *aboveView; /**
* 上面view的透明度
*/
@property (nonatomic, assign) CGFloat aboveViewAlpha; @end
//
// CombinationView.m
// ChangeColorLabel
//
// Created by YouXianMing on 14/11/15.
// Copyright (c) 2014年 YouXianMing. All rights reserved.
// #import "CombinationView.h" typedef enum : NSUInteger {
Above_View = 0x11,
Bottom_View,
} ENUM_VIEW; @implementation CombinationView #pragma mark - 上面的view与下面的view
@synthesize bottomView = _bottomView;
@synthesize aboveView = _aboveView;
@synthesize aboveViewAlpha = _aboveViewAlpha; - (void)setBottomView:(UIView *)bottomView {
self.bounds = bottomView.bounds;
bottomView.frame = bottomView.bounds;
_bottomView = bottomView; _aboveView.tag = Above_View;
_bottomView.tag = Bottom_View; [self addSubview:bottomView];
[self bringSubviewToFront:[self viewWithTag:Above_View]];
}
- (UIView *)bottomView {
return _bottomView;
} - (void)setAboveView:(UIView *)aboveView {
self.bounds = aboveView.bounds;
aboveView.frame = aboveView.bounds;
_aboveView = aboveView; _aboveView.tag = Above_View;
_bottomView.tag = Bottom_View; [self addSubview:aboveView];
[self bringSubviewToFront:[self viewWithTag:Above_View]];
}
- (UIView *)aboveView {
return _aboveView;
} - (void)setAboveViewAlpha:(CGFloat)aboveViewAlpha {
_aboveView.alpha = aboveViewAlpha;
}
- (CGFloat)aboveViewAlpha {
return _aboveView.alpha;
} @end
显示时候的源码:
//
// ViewController.m
// ChangeColorLabel
//
// Created by YouXianMing on 14/11/15.
// Copyright (c) 2014年 YouXianMing. All rights reserved.
// #import "ViewController.h"
#import "CombinationView.h" @interface ViewController () @property (nonatomic, strong) NSTimer *timer;
@property (nonatomic, strong) CombinationView *tmpView; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor blackColor]; // 普通label
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(, , , )];
label.center = self.view.center;
label.textAlignment = NSTextAlignmentCenter;
label.font = [UIFont fontWithName:@"HelveticaNeue-Thin" size:];
label.text = @"YouXianMing";
label.textColor = [UIColor whiteColor]; // 截图
UIView *snapShot = [label snapshotViewAfterScreenUpdates:YES]; // 更新的label
label.textColor = [UIColor redColor]; // 组合器
self.tmpView = [CombinationView new];
self.tmpView.aboveView = label;
self.tmpView.bottomView = snapShot;
self.tmpView.center = self.view.center; // 添加view
[self.view addSubview:self.tmpView]; // 定时器
_timer = [NSTimer scheduledTimerWithTimeInterval:3.5f
target:self
selector:@selector(doAnimation)
userInfo:nil
repeats:YES];
} - (void)doAnimation {
// 做动画测试
[UIView animateWithDuration:1.5 animations:^{
self.tmpView.aboveViewAlpha = .f;
} completion:^(BOOL finished) {
[UIView animateWithDuration:1.5 animations:^{
self.tmpView.aboveViewAlpha = .f;
} completion:^(BOOL finished) { }];
}];
} @end
手机图片源码:
//
// ViewController.m
// ChangeColorLabel
//
// Created by YouXianMing on 14/11/15.
// Copyright (c) 2014年 YouXianMing. All rights reserved.
// #import "ViewController.h"
#import "CombinationView.h" @interface ViewController () @property (nonatomic, strong) NSTimer *timer;
@property (nonatomic, strong) CombinationView *tmpView; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor blackColor]; UIImageView *imageView1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"iPhone"]];
UIImageView *imageView2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"iPhoneOne"]]; // 组合器
self.tmpView = [CombinationView new];
self.tmpView.aboveView = imageView1;
self.tmpView.bottomView = imageView2;
self.tmpView.center = self.view.center; // 添加view
[self.view addSubview:self.tmpView]; // 定时器
_timer = [NSTimer scheduledTimerWithTimeInterval:3.5f
target:self
selector:@selector(doAnimation)
userInfo:nil
repeats:YES];
} - (void)doAnimation {
// 做动画测试
[UIView animateWithDuration:1.5 animations:^{
self.tmpView.aboveViewAlpha = .f;
} completion:^(BOOL finished) {
[UIView animateWithDuration:1.5 animations:^{
self.tmpView.aboveViewAlpha = .f;
} completion:^(BOOL finished) { }];
}];
} @end
实现UILabel渐变色效果的更多相关文章
- 通过CAGradientLayer制作渐变色效果(转)
转载自:http://blog.it985.com/7986.html 看了极客学院的视频之后写的一篇博客,觉得不错,还是作为笔记使用. 简单介绍一下CAGradientLayer吧. Gradien ...
- iOS高仿微信项目、阴影圆角渐变色效果、卡片动画、波浪动画、路由框架等源码
iOS精选源码 iOS高仿微信完整项目源码 Khala: Swift 编写的iOS/macOS 路由框架 微信左滑删除效果的实现与TableViewCell的常用样式介绍 实现阴影圆角并存,渐变色背景 ...
- Android背景渐变色效果
Android设置背景色可以通过在res/drawable里定义一个xml,如下: [代码]xml代码: 1 <?xml version="1.0" encoding=&qu ...
- css实现背景渐变色效果
webkit内核的浏览器,例如(chrome,safari等) background:-webkit-gradient(linear,0 0,0 100%,from(#000000),to(#ffff ...
- 兼容主流浏览器的css渐变色
网页中的渐变色区域,渐变色背景,一般都是通过ps图片方法来实现,但是图片放得多了会影响网页的打开速度,本文介绍的就是用纯 CSS 实现 IE .Firefox.Chrome 和 和Safari都支持的 ...
- iOS - AutoLayout
前言 NS_CLASS_AVAILABLE_IOS(6_0) @interface NSLayoutConstraint : NSObject @available(iOS 6.0, *) publi ...
- asp.net 创建文字特效
相信word 中的 艺术字 功能大家都不陌生.今天, 我们就利用C#来制作几款自己的艺术字, 可能会对我们了解字体图像的制作原理有一些帮助. 至于有没有使用价值我保持沉默. 一. 投影效果 程序运行效 ...
- C#制作艺术字
相信 Word 中的 艺术字 功能大家都不陌生, 前面这个 "Word" 单词就是它所为. 今天, 我们就利用C#来制作几款自己的艺术字, 可能会对我们了解字体图像的制作原理有一 ...
- iOS中常用技术链接
1.弹幕技术 http://www.jianshu.com/p/f39b8abc8008 2.通过CAGradientLayer制作渐变色效果 http://blog.it985.com/7986.h ...
随机推荐
- (转)基于keepalived搭建MySQL的高可用集群
基于keepalived搭建MySQL的高可用集群 原文:http://www.cnblogs.com/ivictor/p/5522383.html MySQL的高可用方案一般有如下几种: keep ...
- (转)centos7.0安装配置DRBD
原文:http://gushiren.blog.51cto.com/3392832/1685207 首先确保两台机器时间同步,配置ssh. 方法一通过yum源安装:yum安装默认路径是/etc/drb ...
- Full Text Search 实现Sort的实现方案
CREATE TABLE dbo.pageStore( ID int NOT NULL, StoreName varchar(50) NULL, OwnerOccupation varchar(50) ...
- table定位
Table定位 在 web 页面中经常会遇到 table 表格,特别是后台操作页面比较常见.本篇详细讲解 table 表格如何定位. 1.1 table特性 1.table 页面查看源码一般有这几个明 ...
- how to run windows programs on a MAC?
How to run windows programs on a MAC? We could use wine or Wine Bottler which is based on wine and p ...
- 通过反射获取及调用方法(Method)
1.获取方法使用反射获取某一个类中的方法,步骤:①找到获取方法所在类的字节码对象②找到需要被获取的方法 Class类中常用方法: public Method[] getMethods():获取包括自身 ...
- 面试题目: 获取服务器IP和客户端IP
[面试题目] 怎么获取服务器IP和客户端IP地址? I. PHP获取客户端IP, 可通过下面系统变量 1. $_SERVER['Remote_Addr'] 2. $_SERVER['HTTP_CLIE ...
- Mybatis的输入映射和输出映射
一.输入映射 通过parameterType指定输入参数类型,类型可以是简单类型.HashMap.pojo的包装类型. 1.简单类型 映射文件: <!-- 查询sql语句配置使用se ...
- JS原型与原型链图解
- MySql数据库与JDBC编程二
DML语法语句:主要操作数据表中的数据,完成插入新数据,修改已有数据,删除不要的数据的任务 1,insert into 语句 用于向指定表插入数据,一次只能插入一条记录:insert into tab ...