UILabel设置字体发光效果
来源:互联网 发布:制作歌词软件 编辑:程序博客网 时间:2024/05/16 05:52
1、新建一个继承自UILabel的类
2、在这个类中定义red、green、blue三个颜色值变量和一个发光范围变量glowSize。
3、重写UILable的drawTextInRect方法,并使用CGContextRef来进行绘制。
.h文件
@interface FBGlowLabel : UILabel //定义颜色值全局变量和放大值全局变量 @property(assign ,nonatomic) float red; @property(assign ,nonatomic) float green; @property(assign ,nonatomic) float blue; @property(assign ,nonatomic) float glowSize;
.m文件
@implementation FBGlowLabel -(id) initWithFrame: (CGRect)frame { if ((self = [super initWithFrame:frame])) { //初始化 red = 0.0f; green = 0.50f; blue = 1.0f; glowSize=40.0f; } return self; } //重写UILable类的drawTextInRect方法 -(void) drawTextInRect: (CGRect)rect { //定义阴影区域 CGSize textShadowOffest = CGSizeMake(0, 0); //定义RGB颜色值 float textColors[] = {red, green, blue, 1.0}; //获取绘制上下文 CGContextRef ctx = UIGraphicsGetCurrentContext(); //保存上下文状态 CGContextSaveGState(ctx); //为上下文设置阴影 CGContextSetShadow(ctx, textShadowOffest, glowSize); //设置颜色类型 CGColorSpaceRef textColorSpace = CGColorSpaceCreateDeviceRGB(); //根据颜色类型和颜色值创建CGColorRef颜色 CGColorRef textColor = CGColorCreate(textColorSpace, textColors); //为上下文阴影设置颜色,阴影颜色,阴影大小 CGContextSetShadowWithColor(ctx, textShadowOffest, size, textColor); [super drawTextInRect:rect]; //释放 CGColorRelease(textColor); CGColorSpaceRelease(textColorSpace); //重启上下文 CGContextRestoreGState(ctx); }
0 0
- UILabel设置字体发光效果
- UILabel发光字体
- 字体发光的UILabel
- UILabel添加发光效果
- UILabel发光字效果
- Android发光字体效果
- 设置边缘发光效果
- css做字体发光效果
- Android闪闪发光字体效果
- Android闪闪发光字体效果
- 新手自定义学习UILabel文字发光效果
- UIlabel 最小字体设置。
- UIlabel设置字体
- [UILabel]设置不同颜色、字体
- CSS实现盒子与字体发光效果
- CSS3发光字体几种效果
- HTML打字机和字体发光效果
- 字体发光
- coreseek多表配置文件
- vim 快捷键
- ckeditor详细配置与使用说明
- dojo中lang.hitch()用法
- PAT 1011. A+B和C C语言
- UILabel设置字体发光效果
- 缓存技术之Ehcache(2)究竟什么时候可以使用Ehcache缓存
- 总结一下最近学到的10个JS技巧
- 关于SSH三大框架注解的问题
- 2016.0802 - 0803 cell添加控件/类名添加前缀/在线绘制流程图
- 【POJ 1321】棋盘问题(DFS)
- Python xrange与range的区别
- eclipse:an error occurred while filtering resources
- 百度面试逻辑题