支持辉光效果的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. darknet

    darknet第二作者:https://github.com//AlexeyAB/darknet#how-to-train-to-detect-your-custom-objects yolov3实现 ...

  2. 详解使用 Tarjan 求 LCA 问题(图解)

    LCA问题有多种求法,例如倍增,Tarjan. 本篇博文讲解如何使用Tarjan求LCA. 如果你还不知道什么是LCA,没关系,本文会详细解释. 在本文中,因为我懒为方便理解,使用二叉树进行示范. L ...

  3. Codeforces Round #284 (Div. 1) C. Array and Operations 二分图匹配

    因为只有奇偶之间有操作, 可以看出是二分图, 然后拆质因子, 二分图最大匹配求答案就好啦. #include<bits/stdc++.h> #define LL long long #de ...

  4. CSS------让ul中高度不同的li底部对齐

    如图: 代码:(需要将li中vertical-align属性设置为bottom) <ul style="margin-top:50px"> <li style=& ...

  5. P1006 传纸条 多维DP

    题目描述 小渊和小轩是好朋友也是同班同学,他们在一起总有谈不完的话题.一次素质拓展活动中,班上同学安排做成一个mm行nn列的矩阵,而小渊和小轩被安排在矩阵对角线的两端,因此,他们就无法直接交谈了.幸运 ...

  6. fpm 制作rpm包

    使用fpm命令制作rpm包并安装 工作中有如下情况需要将文件打包rpm: 避免重复工作,将源码程序打包为rpm 使用yum发布项目,项目打包为rpm 将自己写好的程序打包为rpm,提供给用户下载 其他 ...

  7. 006.KVM虚机克隆

    一 KVM宿主机内克隆 1.1 查看虚拟机配置 [root@kvm-host ~]# cat /etc/libvirt/qemu/vm01-centos6.8.xml ………… [root@kvm-h ...

  8. rabbitmq学习(三) —— 工作队列

    工作队列,又称任务队列,主要思想是避免立即执行资源密集型任务,并且必须等待完成.相反地,我们进行任务调度,我们将一个任务封装成一个消息,并将其发送到队列.工作进行在后台运行不断的从队列中取出任务然后执 ...

  9. 数据包编辑工具bittwiste

    数据包编辑工具bittwiste   bittwiste是数据包重放工具bittwist的一个工具.该工具可以编辑修改PCAP抓包文件.该工具提供数据包过滤功能,如根据范围和时间过滤.同时,该工具支持 ...

  10. BZOJ2888 : 资源运输

    显然资源集合处就是树的重心,这题需要动态维护树的重心. 每个连通块以重心为根,用link-cut tree维护每个点的子树大小以及子树内所有点到它的距离和. 合并两个连通块时,考虑启发式合并,暴力往大 ...