iOS_带发光效果的Label
2016-08-05 16:35
531 查看
//
// GlowLabel.h
// 帅哥句子
//
// Created by beyond on 16/8/5.
// Copyright © 2016年 beyond. All rights reserved.
// 发光的Label
#import <UIKit/UIKit.h>
@interface GlowLabel : UILabel
//定义颜色值全局变量和放大值全局变量
@property(assign,nonatomic)float redValue;
@property(assign,nonatomic)float greenValue;
@property(assign,nonatomic)float blueValue;
@property(assign,nonatomic)float size;
@end
//
// GlowLabel.m
// 帅哥句子
//
// Created by beyond on 16/8/5.
// Copyright © 2016年 beyond. All rights reserved.
//
#import "GlowLabel.h"
@implementation GlowLabel
@synthesize redValue;
@synthesize greenValue;
@synthesize blueValue;
@synthesize size;
-(id) initWithFrame: (CGRect)frame {
if ((self = [super initWithFrame:frame])) {
//变量初始化
redValue = 1.0f;
greenValue = 1.0f;
blueValue = 1.0f;
size=8.0f;//20.0f;
}
return self;
}
//重写UILable类的drawTextInRect方法
-(void) drawTextInRect: (CGRect)rect {
//定义阴影区域
CGSize textShadowOffest = CGSizeMake(0, 0);
//定义RGB颜色值
CGFloat textColorValues[] = {redValue, greenValue, blueValue, 1.0};
//获取绘制上下文
CGContextRef ctx = UIGraphicsGetCurrentContext();
//保存上下文状态
CGContextSaveGState(ctx);
//为上下文设置阴影
CGContextSetShadow(ctx, textShadowOffest, size);
//设置颜色类型
CGColorSpaceRef textColorSpace = CGColorSpaceCreateDeviceRGB();
//根据颜色类型和颜色值创建CGColorRef颜色
CGColorRef textColor = CGColorCreate(textColorSpace, textColorValues);
//为上下文阴影设置颜色阴影颜色阴影大小
CGContextSetShadowWithColor(ctx, textShadowOffest, size, textColor);
[super drawTextInRect:rect];
//释放
CGColorRelease(textColor);
CGColorSpaceRelease(textColorSpace);
//重启上下文
CGContextRestoreGState(ctx);
}
@end
// GlowLabel.h
// 帅哥句子
//
// Created by beyond on 16/8/5.
// Copyright © 2016年 beyond. All rights reserved.
// 发光的Label
#import <UIKit/UIKit.h>
@interface GlowLabel : UILabel
//定义颜色值全局变量和放大值全局变量
@property(assign,nonatomic)float redValue;
@property(assign,nonatomic)float greenValue;
@property(assign,nonatomic)float blueValue;
@property(assign,nonatomic)float size;
@end
//
// GlowLabel.m
// 帅哥句子
//
// Created by beyond on 16/8/5.
// Copyright © 2016年 beyond. All rights reserved.
//
#import "GlowLabel.h"
@implementation GlowLabel
@synthesize redValue;
@synthesize greenValue;
@synthesize blueValue;
@synthesize size;
-(id) initWithFrame: (CGRect)frame {
if ((self = [super initWithFrame:frame])) {
//变量初始化
redValue = 1.0f;
greenValue = 1.0f;
blueValue = 1.0f;
size=8.0f;//20.0f;
}
return self;
}
//重写UILable类的drawTextInRect方法
-(void) drawTextInRect: (CGRect)rect {
//定义阴影区域
CGSize textShadowOffest = CGSizeMake(0, 0);
//定义RGB颜色值
CGFloat textColorValues[] = {redValue, greenValue, blueValue, 1.0};
//获取绘制上下文
CGContextRef ctx = UIGraphicsGetCurrentContext();
//保存上下文状态
CGContextSaveGState(ctx);
//为上下文设置阴影
CGContextSetShadow(ctx, textShadowOffest, size);
//设置颜色类型
CGColorSpaceRef textColorSpace = CGColorSpaceCreateDeviceRGB();
//根据颜色类型和颜色值创建CGColorRef颜色
CGColorRef textColor = CGColorCreate(textColorSpace, textColorValues);
//为上下文阴影设置颜色阴影颜色阴影大小
CGContextSetShadowWithColor(ctx, textShadowOffest, size, textColor);
[super drawTextInRect:rect];
//释放
CGColorRelease(textColor);
CGColorSpaceRelease(textColorSpace);
//重启上下文
CGContextRestoreGState(ctx);
}
@end
相关文章推荐
- [iOS]Label拥有光晕扫过效果
- label 发光效果
- IOS小技巧——如何润色一个Label, 一个label中,展现多种字体效果(图文混编 1)
- 取消IOS对App Icon的自动发光(gloss,mask)效果
- IOS 按钮点击发光效果
- iOS动画——辉光效果(Label)
- [置顶] ios 全景浏览效果demo
- iOS开发(OC)——绕圆心旋转效果
- ios 设置label 不同字体大小颜色
- iOS开发使用半透明模糊效果方法整理
- iOS开发之使用Storyboard预览UI在不同屏幕上的运行效果
- IOS 之 UITableView 实现点击展开裂缝效果
- iOS 获取label上点击位置的字符位置
- ios 去除按钮的按下效果(阴影)
- iOS自定义Tab按钮去掉按下效果
- ios实现图片动画效果
- 8个LED依次循环发光,3种显示效果,要求通过按钮切换
- 【代码笔记】iOS-文字走马灯效果
- 实现类似 iOS 5 推送通知效果的代码例子
- 【iOS发展-81】setNeedsDisplay刷新显卡,并CADisplayLink它用来模拟计时器效果