将标志性的 FontAwesome 字体带给 iOS。
将以下内容添加到您的 Podfile
中:
pod 'FontAwesome'
这将自动将辅助文件和字体资源包含到您的应用程序中。
首先,确保您已经在项目中包含 FontAwesome.ttf
,并在项目 plist 文件的 UIAppFonts
键中包含名为 FontAwesome.ttf
的字符串项。
然后,将 NSString+FontAwesome
类别添加到项目中。
UILabel *label = [...]
label.font = [UIFont fontWithName:kFontAwesomeFamilyName size:20];
您现在可以使用枚举来使用所有不同的图标字符
label.text = [NSString fontAwesomeIconStringForEnum:FAGithub];
或者,您可以使用此处列出的类标识符来引用它们 http://fortawesome.github.com/Font-Awesome/#all-icons
label.text = [NSString fontAwesomeIconStringForIconIdentifier:@"fa-github"];
就是这样!有关更多信息,请查看小巧的示例项目!
现在 FAImageView 已扩展,并包含一个新的属性 defaultView
,当图像设置为 nil 时显示。
可以将字体 awesome 图标用作图像视图的默认占位符。
FAImageView *imageView = [[FAImageView alloc] initWithFrame:CGRectMake(0.f, 0.f, 100.f, 100.f)];
imageView.image = nil;
[imageView setDefaultIconIdentifier:@"fa-github"];
(从 https://github.com/alexdrone/ios-fontawesome 分支,可作为一个 CocoaPod 使用)
自 Font Awesome 3.0 起不再需要贡献力量,但是仍然非常感谢:“Font Awesome by Dave Gandy - http://fontawesome.io”。