mirror of
https://github.com/material-components/material-components-ios.git
synced 2026-02-20 08:27:32 +08:00
* [ActivityIndicator] Swift first in README * [AnimationTiming] Swift first in readme. * [AppBar] Swift first in readme. * [ButtonBar] Swift first in readme. * [Buttons] Swift first in readme. * [CollectionLayoutAttributes] Swift first in readme * [Collections] Swift first in readme. * [Dialogs] Swift first in readme. * [FeatureHighlight] Swift first in readme. * [FlexibleHeader] Swift first in readme. * [FontDiskLoader] Swift first in readme. * [HeaderStackView] Swift first in readme. * [Ink] Swift first in readme. * [NavigationBar] Swift first in readme. * [OverlayWindow] Adding missing site comments. Swift first in readme. * [PageControl] Swift first in readme. * [Palettes] Swift first in readme. * [ProgressView] Swift first in readme. * [RobotoFontLoader] Swift first in readme. * [ShadowElevations] Swift first in readme. * [ShadowLayer] Swift first in readme. * [Slider] Swift first in readme. * [Snackbar] Swift first in readme. * [SpritedAnimationView] Swift first in readme. * [Switch] Swift first in readme. * [Typography] Swift first in readme. * [ShadowLayer] Reducing font size in readme. * [Switch] Reducing font size in readme.
#FontDiskLoader
Registers a single custom font asset from disk
Material Design Specifications
API Documentation
Overview
In order to use custom fonts on iOS the font assets need to be registered before they can be used. Font Disk Loader lazily registers your custom fonts.
Installation
Requirements
- Xcode 7.0 or higher.
- iOS SDK version 7.0 or higher.
Installation with CocoaPods
To add this component to your Xcode project using CocoaPods, add the following to your Podfile:
pod 'MaterialComponents/FontDiskLoader'
Then, run the following command:
pod install
Importing
Before using Font Disk Loader, you'll need to import it:
Swift
import MaterialComponents
Objective-C
#import "MaterialFontDiskLoader.h"
Usage
Make sure to add your font (or the bundle it is in) to your app target. The FontDiskLoader will lazy
register the font using a CoreText API so adding a the font to your info.plist is not necessary.
All you need to do is initialize the loader with the font name and url to the file and ask for the
font.
Code snippets
Swift
let fontLoader = MDCFontDiskLoader.init(fontName: nameOfFontInFile, fontURL: fontURLOnDisk);
let myFont:UIFont = fontLoader.fontOfSize(16)!;
Objective-C
MDCFontDiskLoader *fontDiskLoader =
[[MDCFontDiskLoader alloc] initWithFontName:nameOfFontInFile URL:fontURLOnDisk];
UIFont *font = [fontDiskLoader fontOfSize:16];