支持辉光效果的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. RandomForest随机森林总结

    1.随机森林原理介绍 随机森林,指的是利用多棵树对样本进行训练并预测的一种分类器.该分类器最早由Leo Breiman和Adele Cutler提出,并被注册成了商标.简单来说,随机森林就是由多棵CA ...

  2. IntelliJ IDEA JRebel Maven Tomcat 实现热部署

    一,JRebel 插件 获取与安装 直接在 IDEA 中操作获取 JRebel 插件 Paste_Image.png Paste_Image.png 安装完成,记得重启 IDEA 使刚才安装的插件生效 ...

  3. ERP合同管理(二十七)

    需要实现的基本业务: 相关的用例图: 相关业务的封装: 相关的约定: 合同信息添加业务流程: 添加的存储过程 SET QUOTED_IDENTIFIER ON SET ANSI_NULLS ON GO ...

  4. #JS attr和prop的区别

    HTML元素固有属性:使用prop方法 HTML元素自定义属性:使用attr方法

  5. Linux磁盘空间扩容(LVM)

    Linux磁盘空间扩容(lvm) 随着系统的运行时间增长,业务数据的增长,原有磁盘的空间会存在空间不足情况,导致系统不能正常运行,或者系统管理员磁盘没有完全划完,根据使用者的需求自行划分.那么怎么才能 ...

  6. 2018年湘潭大学程序设计竞赛 F - maze

    把点抽出来 跑个最短路就好啦. #include<bits/stdc++.h> #define LL long long #define pii pair<int,int> # ...

  7. 【Java】 大话数据结构(17) 排序算法(4) (归并排序)

    本文根据<大话数据结构>一书,实现了Java版的归并排序. 更多:数据结构与算法合集 基本概念 归并排序:将n个记录的序列看出n个有序的子序列,每个子序列长度为1,然后不断两两排序归并,直 ...

  8. SpringBoot详细研究-02数据访问

    Springboot对数据访问部分提供了非常强大的集成,支持mysql,oracle等传统数据库的同时,也支持Redis,MongoDB等非关系型数据库,极大的简化了DAO的代码,尤其是Spring ...

  9. Redis指令与数据结构(二)

    0.Redis目录结构 1)Redis介绍及部署在CentOS7上(一) 2)Redis指令与数据结构(二) 3)Redis客户端连接以及持久化数据(三) 4)Redis高可用之主从复制实践(四) 5 ...

  10. html (第四本书第四章参考)

    上机1 <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8 ...