支持辉光效果的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. .NetCore源码阅读笔记系列之Security (二) 自定义认证实践

    通过前面对AddCookie 或者 AddOpenIdConnect 等了解,其实里面都实现了一个AuthenticationHandler<TOptions>的认证处理,接下来我们来简单 ...

  2. AndroidStudio3.0以上版本的坑

    原文:https://blog.csdn.net/ytfunnysite/article/details/78864556 1.Error:Failed to resolve: com.android ...

  3. Java第三阶段学习(十、XML学习)

    一.XML学习 1.模拟Servlet执行 在学习完前端及java与数据库后,将进行WEB编程阶段的学习.在WEB编程中,可以通过浏览器访问WEB服务器上的数据.这时WEB服务器就相当于另一台计算机. ...

  4. 配置免SSH

    在要远程登录别人的服务器中生成授权标识:ssh-keygen -t rsa上传至需被免登录的服务器:scp ~/.ssh/id_rsa.pub root@xx.xx.xx.xx:/root/.ssh/ ...

  5. django 使用 request 获取浏览器发送的参数

    django 使用 request 获取浏览器发送的参数     转载请注明出处 https://blog.csdn.net/fanlei5458/article/details/80638348 获 ...

  6. 洛谷 P1135 奇怪的电梯

    题目描述 呵呵,有一天我做了一个梦,梦见了一种很奇怪的电梯.大楼的每一层楼都可以停电梯,而且第i层楼(1<=i<=N)上有一个数字Ki(0<=Ki<=N).电梯只有四个按钮:开 ...

  7. JAVA中的email正则表达式

    说到正则表达式,网上有很多的通用的表达式,可是事实上说来,一般人的都 不愿意去拿来研究,就是拿来就直接用就行了.可是,事实上,可能有些时候,项目中或公司里的实际情况不一样,得要修改一下正则表达式的,根 ...

  8. .net 中的async,await理解

    理解: 1.async修饰的方法可理解为异步方法(必须要配合await,否则和普通方法无异)2.当async方法执行遇到await,则立即将控制权转移到async方法的调用者3.由调用者决定是否需要等 ...

  9. AMD K7以来核心架构一览表

    转载或拿走使用请注明出处,谢谢! 注:K10以前AMD的CPU型号主要用PR值标称,故此表中未表示其准确型号

  10. CentOS 7 上安装vim 解決 centos -bash: vim: command not found

    用CentOS上使用vim竟然用不了,报错没有该命令 centos -bash: vim: command not found 那么如何安裝 vim 呢? ---------------------- ...