支持辉光效果的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的更多相关文章

  1. 使用CALayer制作View的辉光效果

    使用CALayer制作View的辉光效果 实现以下的辉光效果: 思路是这样子的: 1. 创建好需要实现辉光效果的View 2. 对这个View进行截图 3. 将这个截图重新添加进View中 4. 对这 ...

  2. GraphicsLab Project之辉光(Glare,Glow)效果 【转】

    作者:i_dovelemon 日期:2016 / 07 / 02 来源:CSDN 主题:Render to Texture, Post process, Glare, Glow, Multi-pass ...

  3. Shimmer辉光动画效果

    Shimmer辉光动画效果 效果 源码 https://github.com/facebook/Shimmer https://github.com/YouXianMing/Animations // ...

  4. 辉光UIView的category

    辉光UIView的category 本人视频教程系类   iOS中CALayer的使用 效果如下: 源码: UIView+GlowView.h 与 UIView+GlowView.m // // UI ...

  5. 辉光的UIView

    辉光的UIView 辉光UIView使用了一个UIView的一个category,名为UIView+Glow,请自行到github上查找. 源码如下: // // RootViewController ...

  6. 闹钟AlarmAndMusic 和支持播放音乐效果《IT蓝豹》

    闹钟AlarmAndMusic 和支持播放音乐效果的,上下滑动调整时间和页面旋转风车效果,由于制作的gif有些问题,效果不明显,欢迎下载使用看看真实的效果.本例子主要由AlertActivity和Al ...

  7. CSS3实现文字扫光效果

    本篇文章由:http://xinpure.com/css3-text-light-sweep-effect/ CSS3 实现的文字扫光效果,几乎可以和 Flash 相媲美了 效果解析 我们分析一下实现 ...

  8. WPF 实现跑马灯效果的Label控件,数据绑定方式实现

    原文:WPF 实现跑马灯效果的Label控件,数据绑定方式实现 项目中需要使用数据绑定的方式实现跑马灯效果的Label,故重构了Label控件:具体代码如下 using System; using S ...

  9. pixijs shader贴图扫光效果

    pixijs shader贴图扫光效果 直接贴代码 const app = new PIXI.Application({ transparent: true }); document.body.app ...

随机推荐

  1. java Comparator和Comparable(比较器)

    Comparable: 一个类实现了Camparable接口则表明这个类的对象之间是可以相互比较的,这个类对象组成的集合就可以直接使用sort方法排序,sort方法调用compareTo()方法里定义 ...

  2. Win7系统Chrome浏览器缓存查看技巧介绍(转)

    1.Chrome下提供了一个命令chrome://cache,可以查看到保留下来的缓存; 2.但是,当你点击缓存文件,Chrome却并非打开缓存源文件,而是如图所示的二进制编码文件; 3.在Win7系 ...

  3. Vuejs 高仿饿了么外卖APP 百度云视频教程下载

    Vuejs 高仿饿了么外卖APP 百度云视频教程下载 链接:https://pan.baidu.com/s/1KPbKog0qJqXI-2ztQ19o7w 提取码: 关注公众号[GitHubCN]回复 ...

  4. Python3 turtle安装和使用教程

    Python3 turtle安装和使用教程   Turtle库是Python语言中一个很流行的绘制图像的函数库,想象一个小乌龟,在一个横轴为x.纵轴为y的坐标系原点,(0,0)位置开始,它根据一组函数 ...

  5. 001.DHCP简介

    一 DHCP概念 DHCP指动态主机配置协议,是一个局域网的网络协议,使用UDP协议工作. 二 应用 为大量客户机自动分配地址,提供集中管理 减轻管理和维护成本,提高网络配置效率 三 分配的主要信息 ...

  6. Mysql Lock wait timeout exceeded; try restarting transaction的问题

    今天在后台跑任务的时候,发现了数据库报错1205 - Lock wait timeout exceeded; try restarting transaction.问题原因是因为表的事务锁,以下是解决 ...

  7. Xamarin iOS教程之申请付费开发者账号下载证书

    Xamarin iOS教程之申请付费开发者账号下载证书 Xamarin iOS使用真机测试应用程序 在讲解iOS Simulator时,已经提到了虽然iOS Simulator可以模仿真实的设备,但是 ...

  8. POJ.1379.Run Away(模拟退火)

    题目链接 POJ输出不能用%lf! mmp从4:30改到6:00,把4:30交的一改输出也过了. 于是就有了两份代码.. //392K 500MS //用两点构成的矩形更新,就不需要管边界了 #inc ...

  9. 喵哈哈村的魔法考试 Round #1 (Div.2) 题解

    喵哈哈村的魔法考试 Round #1 (Div.2) 题解 特别感谢出题人,qscqesze. 也特别感谢测题人Xiper和CS_LYJ1997. 没有他们的付出,就不会有这场比赛. A 喵哈哈村的魔 ...

  10. Codeforces Round #369 (Div. 2) B. Chris and Magic Square 水题

    B. Chris and Magic Square 题目连接: http://www.codeforces.com/contest/711/problem/B Description ZS the C ...