使用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的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: (Python编程)Pickle对象
- 下一篇: 好看的UI界面