支持辉光效果的Label
支持辉光效果的Label

效果

源码
https://github.com/YouXianMing/UI-Component-Collection 中的 FBGlowLabel
//
// FBGlowLabel.h
//
// Created by YouXianMing on 16/8/3.
// Copyright © 2016年 YouXianMing. All rights reserved.
//
// https://github.com/lyokato/fbglowlabel
// #import <UIKit/UIKit.h> @interface FBGlowLabel : UILabel /**
* Glow size, default is 0.f.
*/
@property (nonatomic) CGFloat glowSize; /**
* Glow color, default is clear color.
*/
@property (nonatomic, strong) UIColor *glowColor; /**
* Inner glow size, default is 0.f.
*/
@property (nonatomic) CGFloat innerGlowSize; /**
* Inner glow color, default is clear color.
*/
@property (nonatomic, strong) UIColor *innerGlowColor; @end
//
// FBGlowLabel.m
//
// Created by YouXianMing on 16/8/3.
// Copyright © 2016年 YouXianMing. All rights reserved.
// #import "FBGlowLabel.h" @implementation FBGlowLabel - (id)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { [self setup];
} return self;
} - (id)initWithCoder:(NSCoder *)coder { if (self = [super initWithCoder:coder]) { [self setup];
} return self;
} - (void)setup { self.glowSize = 0.0f;
self.glowColor = [UIColor clearColor]; self.innerGlowSize = 0.0f;
self.innerGlowColor = [UIColor clearColor];
} - (void)drawTextInRectForIOS7:(CGRect)rect { CGContextRef ctx = UIGraphicsGetCurrentContext(); UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0.0); [super drawTextInRect:rect];
UIImage *textImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext(); CGContextSaveGState(ctx); if (_glowSize > ) { CGContextSetShadow(ctx, CGSizeZero, _glowSize);
CGContextSetShadowWithColor(ctx, CGSizeZero, _glowSize, _glowColor.CGColor);
} [textImage drawAtPoint:rect.origin];
CGContextRestoreGState(ctx); if (_innerGlowSize > ) { UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0.0);
CGContextRef ctx2 = UIGraphicsGetCurrentContext();
CGContextSaveGState(ctx2);
CGContextSetFillColorWithColor(ctx2, [UIColor blackColor].CGColor);
CGContextFillRect(ctx2, rect);
CGContextTranslateCTM(ctx2, 0.0, rect.size.height);
CGContextScaleCTM(ctx2, 1.0, -1.0);
CGContextClipToMask(ctx2, rect, textImage.CGImage);
CGContextClearRect(ctx2, rect);
CGContextRestoreGState(ctx2); UIImage *inverted = UIGraphicsGetImageFromCurrentImageContext();
CGContextClearRect(ctx2, rect); CGContextSaveGState(ctx2);
CGContextSetFillColorWithColor(ctx2, _innerGlowColor.CGColor);
CGContextSetShadowWithColor(ctx2, CGSizeZero, _innerGlowSize, _innerGlowColor.CGColor);
[inverted drawAtPoint:CGPointZero];
CGContextTranslateCTM(ctx2, 0.0, rect.size.height);
CGContextScaleCTM(ctx2, 1.0, -1.0);
CGContextClipToMask(ctx2, rect, inverted.CGImage);
CGContextClearRect(ctx2, rect);
CGContextRestoreGState(ctx2); UIImage *innerShadow = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();
[innerShadow drawAtPoint:rect.origin];
}
} - (void)drawTextInRectForIOS6:(CGRect)rect { CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSaveGState(ctx); if (self.glowSize > ) { CGContextSetShadow(ctx, CGSizeZero, _glowSize);
CGContextSetShadowWithColor(ctx, CGSizeZero, _glowSize, _glowColor.CGColor);
} [super drawTextInRect:rect];
CGContextRestoreGState(ctx); if (_innerGlowSize > ) { UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0.0); CGContextRef ctx2 = UIGraphicsGetCurrentContext();
[super drawTextInRect:rect]; UIImage *textImage = UIGraphicsGetImageFromCurrentImageContext();
CGContextClearRect(ctx2, rect); CGContextSaveGState(ctx2);
CGContextSetFillColorWithColor(ctx2, [UIColor blackColor].CGColor);
CGContextFillRect(ctx2, rect);
CGContextTranslateCTM(ctx2, 0.0, rect.size.height);
CGContextScaleCTM(ctx2, 1.0, -1.0);
CGContextClipToMask(ctx2, rect, textImage.CGImage);
CGContextClearRect(ctx2, rect);
CGContextRestoreGState(ctx2); UIImage *inverted = UIGraphicsGetImageFromCurrentImageContext();
CGContextClearRect(ctx2, rect); CGContextSaveGState(ctx2);
CGContextSetFillColorWithColor(ctx2, _innerGlowColor.CGColor);
CGContextSetShadowWithColor(ctx2, CGSizeZero, _innerGlowSize, _innerGlowColor.CGColor);
[inverted drawAtPoint:CGPointZero];
CGContextTranslateCTM(ctx2, 0.0, rect.size.height);
CGContextScaleCTM(ctx2, 1.0, -1.0);
CGContextClipToMask(ctx2, rect, inverted.CGImage);
CGContextClearRect(ctx2, rect);
CGContextRestoreGState(ctx2); UIImage *innerShadow = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();
[innerShadow drawAtPoint:rect.origin];
}
} - (void)drawTextInRect:(CGRect)rect { if (self.text == nil || self.text.length == ) { return;
} if ([[[UIDevice currentDevice] systemVersion] compare:@"7.0" options:NSNumericSearch] != NSOrderedAscending) { [self drawTextInRectForIOS7:rect]; } else { [self drawTextInRectForIOS6:rect];
}
} @end
//
// ViewController.m
// FBGlowLabel
//
// Created by YouXianMing on 16/8/3.
// Copyright © 2016年 YouXianMing. All rights reserved.
// #import "ViewController.h"
#import "FBGlowLabel.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor blackColor]; FBGlowLabel *glowLabel = [[FBGlowLabel alloc] initWithFrame:self.view.bounds];
[self.view addSubview:glowLabel]; glowLabel.text = @"壹擊必殺";
glowLabel.textAlignment = NSTextAlignmentCenter;
glowLabel.backgroundColor = [UIColor clearColor];
glowLabel.font = [UIFont fontWithName:@"Heiti SC" size:.f];
glowLabel.textColor = [[UIColor cyanColor] colorWithAlphaComponent:0.95f]; glowLabel.glowSize = ;
glowLabel.glowColor = [UIColor cyanColor]; glowLabel.innerGlowSize = ;
glowLabel.innerGlowColor = [[UIColor blackColor] colorWithAlphaComponent:0.25f];
} @end
支持辉光效果的Label的更多相关文章
- 使用CALayer制作View的辉光效果
使用CALayer制作View的辉光效果 实现以下的辉光效果: 思路是这样子的: 1. 创建好需要实现辉光效果的View 2. 对这个View进行截图 3. 将这个截图重新添加进View中 4. 对这 ...
- GraphicsLab Project之辉光(Glare,Glow)效果 【转】
作者:i_dovelemon 日期:2016 / 07 / 02 来源:CSDN 主题:Render to Texture, Post process, Glare, Glow, Multi-pass ...
- Shimmer辉光动画效果
Shimmer辉光动画效果 效果 源码 https://github.com/facebook/Shimmer https://github.com/YouXianMing/Animations // ...
- 辉光UIView的category
辉光UIView的category 本人视频教程系类 iOS中CALayer的使用 效果如下: 源码: UIView+GlowView.h 与 UIView+GlowView.m // // UI ...
- 辉光的UIView
辉光的UIView 辉光UIView使用了一个UIView的一个category,名为UIView+Glow,请自行到github上查找. 源码如下: // // RootViewController ...
- 闹钟AlarmAndMusic 和支持播放音乐效果《IT蓝豹》
闹钟AlarmAndMusic 和支持播放音乐效果的,上下滑动调整时间和页面旋转风车效果,由于制作的gif有些问题,效果不明显,欢迎下载使用看看真实的效果.本例子主要由AlertActivity和Al ...
- CSS3实现文字扫光效果
本篇文章由:http://xinpure.com/css3-text-light-sweep-effect/ CSS3 实现的文字扫光效果,几乎可以和 Flash 相媲美了 效果解析 我们分析一下实现 ...
- WPF 实现跑马灯效果的Label控件,数据绑定方式实现
原文:WPF 实现跑马灯效果的Label控件,数据绑定方式实现 项目中需要使用数据绑定的方式实现跑马灯效果的Label,故重构了Label控件:具体代码如下 using System; using S ...
- pixijs shader贴图扫光效果
pixijs shader贴图扫光效果 直接贴代码 const app = new PIXI.Application({ transparent: true }); document.body.app ...
随机推荐
- python的map,filter,reduce学习
python2,python3中map,filter,reduce区别: 1,在python2 中,map,filter,reduce函数是直接输出结果. 2,在python3中做了些修改,输出前需要 ...
- nginx支持ssl双向认证配置
nginx支持ssl双向认证配置 listen 443; server_name test.com; ssl on; ssl_certificate server.crt; //server端公钥 s ...
- 转:Spring中事物管理
1.什么是事务? 事务是逻辑上的一组操作,这组操作要么全部成功,要么全部失败 2.事物具有四大特性ACID 说到事务,就不得不说其4大特性,主要如下 原子性:(atomicity) 原子性指的是事务是 ...
- DSP 程序的执行时间
在访问TSCL寄存器前要定义 cregister volatile unsigned int TSCL; TSCL/TSCH,它们与CPU同频,共同表示一个64-bit数,CPU运行一个cycle,该 ...
- 8.7 正睿暑期集训营 Day4
目录 2018.8.7 正睿暑期集训营 Day4 A 世界杯(贪心) B 数组(线段树) C 淘汰赛 考试代码 A B C 2018.8.7 正睿暑期集训营 Day4 时间:5h(实际) 期望得分:. ...
- hdu 5752 Sqrt Bo 水题
Sqrt Bo 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5752 Description Let's define the function f ...
- OS X - 在80端口启动Nginx
不知道你是怎么在你的mac上安装nginx的,但是如果你跟我一样: brew install nginx 然后你会发现你的nginx.conf中的端口是8080. 于是你可能像我一样试着把端口改为80 ...
- Spring_之注解事务 @Transactional
spring 事务注解 默认遇到throw new RuntimeException("...");会回滚需要捕获的throw new Exception("...&qu ...
- 李善友《认知升级之第一性原理》--507张PPT全解!_搜狐科技_搜狐网
http://www.sohu.com/a/151470602_733114
- LPC1800 and LPC4300 MCUs
LPC1800 Series microcontrollers At 180 MHz, LPC1800 Series microcontrollers combine the industry's f ...