アイコンフォント便利ですよね。
iOSアプリにも使えるんですよ。
Font Awesome などを利用できるPrideChung/FontAwesomeKit を使ってみました。
how to install
cocoapods利用時は下記でOK
pod 'FontAwesomeKit', '~> 2.1.0'
これで以下のアイコンフォントが利用できます。
恐るべし。
・FontAwesome
・FoundationIcons
・Zocial
・IonIcons
how to use
FAKFontAwesome *starIcon = [FAKFontAwesome circleIconWithSize:15]; [icon addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor]]; cell.statusLabel.attributedText = [[self iconWithStatus:document.status size:10] attributedString];
- (FAKFontAwesome *)iconWithStatus:(NSNumber *)status size:(CGFloat)size { FAKFontAwesome *icon; switch ((DocumentStatus)[status intValue]) { case DocumentStatusReading: icon = [FAKFontAwesome adjustIconWithSize:size]; break; case DocumentStatusDone: icon = [FAKFontAwesome circleOIconWithSize:size]; break; default: icon = [FAKFontAwesome circleIconWithSize:size]; break; } [icon addAttribute:NSForegroundColorAttributeName value:self.view.tintColor]; return icon; }
アイコンの種類毎にインスタンス生成のクラスメソッドが用意されているので
fontsizeを指定してアイコンインスタンスを生成します。
色の変更も簡単です。
setAttributes ではだめでした。また、フォントサイズの変更もiconFontSize propertyで変更するようです。
画像としても利用できます。
UIImage *iconImage = [starIcon imageWithSize:CGSizeMake(15, 15)];
こんな感じ
かなり簡単でいいです。