UIFont category that allows loading local TrueType Font files. This does NOT require defining fonts in the Info.plist file of the project. It is also specifically useful for Cydia Substrate extensions, where modifying the Info.plist is not viable.
NSString *pathToFont = [[NSBundle mainBundle] pathForResource:@"segoeui" ofType:@"ttf"];
UIFont *smallFontFromPath = [UIFont fontWithTTFAtPath:pathToFont size:18.0f];
NSString *pathToFont = [[NSBundle mainBundle] pathForResource:@"segoeui" ofType:@"ttf"];
NSURL *URLToFont = [NSURL fileURLWithPath:pathToFont];
UIFont *smallFontFromURL = [UIFont fontWithTTFAtURL:[NSURL fileURLWithPath:pathToFont] size:18.0f];
- This category requires ARC, as non-ARC code uses different casting semantics. ARC (and UIFont-TTF) makes use of
__bridge
casts. - Errors are generated by means of NSAssert. If NS_BLOCK_ASSERTIONS has been defined errors will not throw exceptions but instead fail silently. In this event, the font returned will be obtained from systemFontOfSize, taking into account the provided size.