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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

使用FontAwesome

發布時間:2025/3/15 编程问答 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用FontAwesome 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

使用FontAwesome

https://github.com/PrideChung/FontAwesomeKit

?

為什么要使用FontAwesome呢,其實,它的字體就是矢量圖,無論是放大還是縮小都不失真的矢量圖哦.

1. 下載源碼,導入文件夾FontAwesomeKit,然后引入頭文件FontAwesomeKit.h

?

2. 使用

// 取得固定的icon以及設定尺寸FAKZocial *twitterIcon = [FAKZocial stackoverflowIconWithSize:50];// 設定相關的屬性 [twitterIcon addAttribute:NSForegroundColorAttributeNamevalue:[UIColor redColor]];// 在UILabel上顯示UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];label.attributedText = [twitterIcon attributedString];[self.view addSubview:label];label.center = self.view.center;

使用是非常簡單的哦,效果如下:

?

3. 高級應用

你以為就顯示出來就沒了么?非也,你想過把字體轉換為路徑么,轉換為路徑后就可以執行各種CoreAnimation的動畫了呢:)

先來試一下CAshapeLayer的動畫路徑:

// 取得固定的icon以及設定尺寸FAKZocial *twitterIcon = [FAKZocial chromeIconWithSize:100];// 設定相關的屬性 [twitterIcon addAttribute:NSForegroundColorAttributeNamevalue:[UIColor blackColor]];// 將icon轉換為貝塞爾曲線UIBezierPath *path = [UIBezierPath pathFromAttributedString:[twitterIcon attributedString]];// 創建shapeLayerCAShapeLayer *shapeLayer = [CAShapeLayer layer];// 獲取pathshapeLayer.path = path.CGPath;// 根據這個path來設定尺寸shapeLayer.bounds = CGPathGetBoundingBox(shapeLayer.path);// 幾何反轉shapeLayer.geometryFlipped = YES;// 一些顏色的填充shapeLayer.fillColor = [UIColor clearColor].CGColor;shapeLayer.strokeColor = [UIColor cyanColor].CGColor;// 設定layer位置shapeLayer.position = self.view.center;[self.view.layer addSublayer:shapeLayer];// 定時器動畫_timer = [[GCDTimer alloc] initInQueue:[GCDQueue mainQueue]];[_timer event:^{shapeLayer.strokeEnd = arc4random()%100/100.f;} timeInterval:NSEC_PER_SEC];[_timer start];

// 取得固定的icon以及設定尺寸FAKZocial *twitterIcon = [FAKZocial chromeIconWithSize:100];// 設定相關的屬性 [twitterIcon addAttribute:NSForegroundColorAttributeNamevalue:[UIColor blackColor]];// 將icon轉換為貝塞爾曲線UIBezierPath *path = [UIBezierPath pathFromAttributedString:[twitterIcon attributedString]];// 創建shapeLayerCAShapeLayer *shapeLayer = [CAShapeLayer layer];// 獲取pathshapeLayer.path = path.CGPath;// 根據這個path來設定尺寸shapeLayer.bounds = CGPathGetBoundingBox(shapeLayer.path);// 幾何反轉shapeLayer.geometryFlipped = YES;// 一些顏色的填充shapeLayer.fillColor = [UIColor blackColor].CGColor;shapeLayer.strokeColor = [UIColor clearColor].CGColor;shapeLayer.position = CGPointMake(50, 50);// 漸變顏色圖層CAGradientLayer *colorLayer = [CAGradientLayer layer];colorLayer.bounds = CGRectMake(0, 0, 120, 120);colorLayer.mask = shapeLayer;colorLayer.colors = @[(id)[UIColor redColor].CGColor,(id)[UIColor greenColor].CGColor,(id)[UIColor yellowColor].CGColor];colorLayer.position = self.view.center;// 設定layer位置 [self.view.layer addSublayer:colorLayer];// 定時器動畫_timer = [[GCDTimer alloc] initInQueue:[GCDQueue mainQueue]];[_timer event:^{colorLayer.speed = 0.5;colorLayer.colors = @[(id)[UIColor colorWithRed:arc4random()%255/255.fgreen:arc4random()%255/255.fblue:arc4random()%255/255.falpha:1].CGColor,(id)[UIColor colorWithRed:arc4random()%255/255.fgreen:arc4random()%255/255.fblue:arc4random()%255/255.falpha:1].CGColor,(id)[UIColor colorWithRed:arc4random()%255/255.fgreen:arc4random()%255/255.fblue:arc4random()%255/255.falpha:1].CGColor,(id)[UIColor colorWithRed:arc4random()%255/255.fgreen:arc4random()%255/255.fblue:arc4random()%255/255.falpha:1].CGColor,(id)[UIColor colorWithRed:arc4random()%255/255.fgreen:arc4random()%255/255.fblue:arc4random()%255/255.falpha:1].CGColor];} timeInterval:NSEC_PER_SEC];[_timer start];

// 取得固定的icon以及設定尺寸FAKZocial *twitterIcon = [FAKZocial chromeIconWithSize:100];// 設定相關的屬性 [twitterIcon addAttribute:NSForegroundColorAttributeNamevalue:[UIColor blackColor]];// 將icon轉換為貝塞爾曲線UIBezierPath *path = [UIBezierPath pathFromAttributedString:[twitterIcon attributedString]];// 創建shapeLayerCAShapeLayer *shapeLayer = [CAShapeLayer layer];// 獲取pathshapeLayer.path = path.CGPath;// 根據這個path來設定尺寸shapeLayer.bounds = CGPathGetBoundingBox(shapeLayer.path);// 幾何反轉shapeLayer.geometryFlipped = YES;// 一些顏色的填充shapeLayer.fillColor = [UIColor redColor].CGColor;shapeLayer.strokeColor = [UIColor clearColor].CGColor;shapeLayer.position = CGPointMake(50, 50);// 漸變顏色圖層CAGradientLayer *colorLayer = [CAGradientLayer layer];colorLayer.bounds = CGRectMake(0, 0, 120, 120);colorLayer.mask = shapeLayer;colorLayer.colors = @[(id)[UIColor redColor].CGColor,(id)[UIColor greenColor].CGColor,(id)[UIColor yellowColor].CGColor];colorLayer.position = self.view.center;// 設定layer位置 [self.view.layer addSublayer:colorLayer];// 旋轉CABasicAnimation *basicAni = \[CABasicAnimationList animationWithRotationZFromValue:-2*M_PI_2 toValue:2*M_PI_2];basicAni.duration = 1.0f;basicAni.repeatCount = HUGE_VALF;[shapeLayer addAnimation:basicAni forKey:nil];// 定時器動畫_timer = [[GCDTimer alloc] initInQueue:[GCDQueue mainQueue]];[_timer event:^{colorLayer.colors = @[(id)[UIColor colorWithRed:arc4random()%255/255.fgreen:arc4random()%255/255.fblue:arc4random()%255/255.falpha:1].CGColor,(id)[UIColor colorWithRed:arc4random()%255/255.fgreen:arc4random()%255/255.fblue:arc4random()%255/255.falpha:1].CGColor,(id)[UIColor colorWithRed:arc4random()%255/255.fgreen:arc4random()%255/255.fblue:arc4random()%255/255.falpha:1].CGColor,(id)[UIColor colorWithRed:arc4random()%255/255.fgreen:arc4random()%255/255.fblue:arc4random()%255/255.falpha:1].CGColor,(id)[UIColor colorWithRed:arc4random()%255/255.fgreen:arc4random()%255/255.fblue:arc4random()%255/255.falpha:1].CGColor];} timeInterval:NSEC_PER_SEC];[_timer start];

?

?

附錄:

??? FAKFontAwesome *starIcon = [FAKFontAwesome asteriskIconWithSize:50];
??? FAKFoundationIcons *bookmarkIcon = [FAKFoundationIcons bookmarkIconWithSize:15];
??? FAKZocial *twitterIcon = [FAKZocial twitterIconWithSize:15];
??? FAKIonIcons *mailIcon = [FAKIonIcons ios7EmailIconWithSize:48];

?

轉載于:https://www.cnblogs.com/YouXianMing/p/3756495.html

總結

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

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