日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

UILabel发光字体

發布時間:2023/12/20 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 UILabel发光字体 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1、新建一個基于UILabel的子類

2、在這個子類中定義red、green、blue三個顏色值變量和一個發光光暈范圍變量size。

3、復寫UILable的drawTextInRect方法,并使用CGContextRef來進行光暈效果繪制。

基本思路就是這樣子了,下面是部分主要代碼:

.h文件

//創建UILable的子類 GlowLable @interface GlowLabel : UILabel//定義顏色值全局變量和放大值全局變量 @property(assign,nonatomic)float redValue; @property(assign,nonatomic)float greenValue; @property(assign,nonatomic)float blueValue; @property(assign,nonatomic)float size;@end
.m文件

@implementation GlowLabel@synthesize redValue; @synthesize greenValue; @synthesize blueValue; @synthesize size;-(id) initWithFrame: (CGRect)frame {if ((self = [super initWithFrame:frame])) {//變量初始化redValue = 0.0f;greenValue = 0.50f;blueValue = 1.0f;size=20.0f;}return self; }//重寫UILable類的drawTextInRect方法 -(void) drawTextInRect: (CGRect)rect {//定義陰影區域CGSize textShadowOffest = CGSizeMake(0, 0);//定義RGB顏色值float 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
最終效果:

總結

以上是生活随笔為你收集整理的UILabel发光字体的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。